Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 10, 2022
1 parent cabb2f4 commit 7bf9908
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 16 deletions.
Empty file.
Empty file.
Empty file.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

This file was deleted.

This file was deleted.

62 changes: 58 additions & 4 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,78 @@ describe('findNodeModule', () => {
});

test('resolves with import', () => {
const result = Resolver.findNodeModule('import', {
const result = Resolver.findNodeModule('exports', {
basedir: conditionsRoot,
conditions: ['import'],
});

expect(result).toEqual(
path.resolve(conditionsRoot, './node_modules/import/file.js'),
path.resolve(conditionsRoot, './node_modules/exports/import.js'),
);
});

test('resolves with require', () => {
const result = Resolver.findNodeModule('require', {
const result = Resolver.findNodeModule('exports', {
basedir: conditionsRoot,
conditions: ['require'],
});

expect(result).toEqual(
path.resolve(conditionsRoot, './node_modules/require/file.js'),
path.resolve(conditionsRoot, './node_modules/exports/require.js'),
);
});

test('gets default when nothing is passed', () => {
const result = Resolver.findNodeModule('exports', {
basedir: conditionsRoot,
conditions: [],
});

expect(result).toEqual(
path.resolve(conditionsRoot, './node_modules/exports/default.js'),
);
});

test('respects order in package.json, not conditions', () => {
const resultImport = Resolver.findNodeModule('exports', {
basedir: conditionsRoot,
conditions: ['import', 'require'],
});
const resultRequire = Resolver.findNodeModule('exports', {
basedir: conditionsRoot,
conditions: ['require', 'import'],
});

expect(resultImport).toEqual(resultRequire);
});

test('supports nested paths', () => {
const result = Resolver.findNodeModule('exports/nested', {
basedir: conditionsRoot,
conditions: [],
});

expect(result).toEqual(
path.resolve(conditionsRoot, './node_modules/exports/nestedDefault.js'),
);
});

test('supports nested conditions', () => {
const resultRequire = Resolver.findNodeModule('exports/deeplyNested', {
basedir: conditionsRoot,
conditions: ['require'],
});
const resultDefault = Resolver.findNodeModule('exports/deeplyNested', {
basedir: conditionsRoot,
conditions: [],
});

expect(resultRequire).toEqual(
path.resolve(conditionsRoot, './node_modules/exports/nestedRequire.js'),
);

expect(resultDefault).toEqual(
path.resolve(conditionsRoot, './node_modules/exports/nestedDefault.js'),
);
});
});
Expand Down

0 comments on commit 7bf9908

Please sign in to comment.