Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(#2): add tests #9

Merged
merged 8 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add tests
vitonsky committed Apr 3, 2024
commit 5345c66bd7a1c16becd121b99ede57e6c26b851b
43 changes: 13 additions & 30 deletions src/import-paths.test.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,11 @@ tester.run('import-paths', rule, {
filename: path.resolve('./src/index.ts'),
code: `import baz from './baz/index';`,
},
{
name: 'import from alias root',
filename: path.resolve('./src/index.ts'),
code: `import baz from '@foo';`,
},
{
name: 'alias import from alias directory',
filename: path.resolve('./src/foo/index.ts'),
@@ -41,40 +46,18 @@ tester.run('import-paths', rule, {
],
invalid: [
{
options: [{}],
name: 'relative import from alias must be fixed',
filename: path.resolve('./src/index.ts'),
code: `import globalFoo from './foo/index';`,
errors: ['Update import to @foo/index'],
output: `import globalFoo from '@foo/index';`,
code: `import z from './foo/x/y/z';`,
errors: ['Update import to @foo/x/y/z'],
output: `import z from '@foo/x/y/z';`,
},
{
options: [{}],
name: 'relative import from alias used in file under another alias must be fixed',
filename: path.resolve('./src/foo/index.ts'),
code: `
// import globalFoo from '../foo/index';
import globalBar from '../bar/index';
import bar1 from '../bar/1';
// import bar2 from 'bar/1/2';
// import bar3 from 'bar/1/2/3';

// import globalBaz from './baz';
// import baz1 from './baz/main';
// import baz2 from '../baz/main';
// import baz3 from '../../baz/main';
`.replace(/\t/g, ''),
errors: ['Update import to @bar/index', 'Update import to @bar/1'],
output: `
// import globalFoo from '../foo/index';
import globalBar from '@bar/index';
import bar1 from '@bar/1';
// import bar2 from 'bar/1/2';
// import bar3 from 'bar/1/2/3';

// import globalBaz from './baz';
// import baz1 from './baz/main';
// import baz2 from '../baz/main';
// import baz3 from '../../baz/main';
`.replace(/\t/g, ''),
code: `import z from '../bar/x/y/z';`,
errors: ['Update import to @bar/x/y/z'],
output: `import z from '@bar/x/y/z';`,
},
],
});