-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a8021
commit aa4dbb8
Showing
5 changed files
with
262 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import QUnit from 'qunit'; | ||
import 'qunit-assertions-extra'; | ||
import { commonAncestorDirectories, getImportableModules } from '../util'; | ||
import { Project } from 'scenario-tester'; | ||
|
||
const { module: Qmodule, test } = QUnit; | ||
|
||
async function generateProject(packageJson = {}) { | ||
const project = new Project('my-package', { | ||
files: { | ||
'package.json': JSON.stringify(packageJson), | ||
src: { | ||
'index.js': 'export default 123', | ||
'module.js': 'export default 123', | ||
nested: { | ||
'module.js': 'export default 123', | ||
}, | ||
}, | ||
dist: { | ||
'index.js': 'export default 123', | ||
'module.js': 'export default 123', | ||
nested: { | ||
'module.js': 'export default 123', | ||
}, | ||
}, | ||
declarations: { | ||
'index.d.ts': 'export default 123', | ||
'module.d.ts': 'export default 123', | ||
nested: { | ||
'module.d.ts': 'export default 123', | ||
}, | ||
}, | ||
lib: { | ||
'module.js': 'export default 123', | ||
}, | ||
}, | ||
}); | ||
|
||
await project.write(); | ||
|
||
return project; | ||
} | ||
|
||
Qmodule('commonAncestorDirectories', function () { | ||
test('returns same dirs if no nested', function (assert) { | ||
const result = commonAncestorDirectories([ | ||
'/a/b/c/index.js', | ||
'/d/index.js', | ||
]); | ||
|
||
assert.deepEqual(result, ['/a/b/c', '/d']); | ||
}); | ||
|
||
test('returns common dirs', function (assert) { | ||
const result = commonAncestorDirectories([ | ||
'/a/b/c/index.js', | ||
'/a/b/index.js', | ||
'/d/index.js', | ||
'/d/e/f/index.js', | ||
]); | ||
|
||
assert.deepEqual(result, ['/a/b', '/d']); | ||
}); | ||
|
||
test('ignores duplicates', function (assert) { | ||
const result = commonAncestorDirectories([ | ||
'/a/b/c/index.js', | ||
'/a/b/index.js', | ||
'/a/b/c/index.js', | ||
'/a/b/index.js', | ||
]); | ||
|
||
assert.deepEqual(result, ['/a/b']); | ||
}); | ||
}); | ||
|
||
Qmodule('importableModules', function (hooks) { | ||
let project: Project; | ||
|
||
hooks.afterEach(function (this: any) { | ||
project?.dispose(); | ||
}); | ||
|
||
test('returns only modules declared in exports', async function (assert) { | ||
project = await generateProject({ | ||
exports: './dist/index.js', | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, ['./dist/index.js']); | ||
}); | ||
|
||
test('ignores types condition', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
types: './declarations/index.d.ts', | ||
default: './dist/index.js', | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, ['./dist/index.js']); | ||
}); | ||
|
||
test('ignores node condition', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
types: './declarations/index.d.ts', | ||
default: './dist/index.js', | ||
}, | ||
'lib/module': { | ||
node: './lib/module.js', | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, ['./dist/index.js']); | ||
}); | ||
|
||
test('supports import condition', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
types: './declarations/index.d.ts', | ||
import: './dist/index.js', | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, ['./dist/index.js']); | ||
}); | ||
|
||
test('supports nested conditions', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
import: { | ||
types: './declarations/index.d.ts', | ||
default: './dist/index.js', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, ['./dist/index.js']); | ||
}); | ||
|
||
test('supports subpaths', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
types: './declarations/index.d.ts', | ||
default: './dist/index.js', | ||
}, | ||
module: { | ||
types: './declarations/module.d.ts', | ||
default: './dist/module.js', | ||
}, | ||
'nested/module': { | ||
types: './declarations/nested/module.d.ts', | ||
default: './dist/nested/module.js', | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, [ | ||
'./dist/index.js', | ||
'./dist/module.js', | ||
'./dist/nested/module.js', | ||
]); | ||
}); | ||
|
||
test('supports globstar patterns', async function (assert) { | ||
project = await generateProject({ | ||
exports: { | ||
'.': { | ||
types: './declarations/index.d.ts', | ||
default: './dist/index.js', | ||
}, | ||
'./*': { | ||
types: './declarations/*.d.ts', | ||
default: './dist/*.js', | ||
}, | ||
}, | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, [ | ||
'./dist/index.js', | ||
'./dist/module.js', | ||
'./dist/nested/module.js', | ||
]); | ||
}); | ||
|
||
test('returns all possible imports when having only main export', async function (assert) { | ||
project = await generateProject({ | ||
main: './dist/index.js', | ||
}); | ||
|
||
const result = await getImportableModules(project.baseDir); | ||
|
||
assert.deepEqual(result, [ | ||
'./declarations/index.d.ts', | ||
'./declarations/module.d.ts', | ||
'./declarations/nested/module.d.ts', | ||
'./dist/index.js', | ||
'./dist/module.js', | ||
'./dist/nested/module.js', | ||
'./index.js', | ||
'./lib/module.js', | ||
'./package.json', | ||
'./src/index.js', | ||
'./src/module.js', | ||
'./src/nested/module.js', | ||
]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters