Skip to content

Commit

Permalink
feat(linter): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 12, 2023
1 parent f0b0d1d commit 28461e1
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tools/eslint-rules/rules/restrict-js-plugin-deep-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ const ruleTester = new TSESLint.RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
});

jest.mock('@nrwl/devkit', () => ({
...jest.requireActual<any>('@nrwl/devkit'),
workspaceRoot: '/root',
}));

ruleTester.run(RULE_NAME, rule, {
valid: [`const example = true;`],
invalid: [],
valid: [
{
code: `import { createLockFile } from 'nx/src/plugins/js';`,
filename: '/root/packages/devkit/src/path/to.ts',
},
{
code: `import { createLockFile } from '../plugins/js';`,
filename: '/root/packages/nx/src/path/to.ts',
},
],
invalid: [
{
errors: [{ messageId: 'noDeepImport' }],
code: `import { createLockFile } from 'nx/src/plugins/js/lock-file/lock-file';`,
filename: '/root/packages/devkit/src/path/to.ts',
},
{
errors: [{ messageId: 'noDeepRelativeImport' }],
code: `import { createLockFile } from '../plugins/js/lock-file/lock-file';`,
filename: '/root/packages/nx/src/path/to.ts',
},
],
});

0 comments on commit 28461e1

Please sign in to comment.