diff --git a/.eslintignore b/.eslintignore index 46f07d99..25b5c4d2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,4 +4,5 @@ /scripts/performance/**/fake_project/ /experiment/**/dist/ /tests/**/root/ +/tests/**/input/ /node_modules/ \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52c1d298..06739e37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: os: [ubuntu-20.04, macos-12, windows-2022] - node: [20.8.0] + node: [22.3.0] runs-on: ${{ matrix.os }} name: test on ${{ matrix.os }} and node ${{ matrix.node }} env: @@ -55,7 +55,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: "20.8.0" + node-version: "22.3.0" - name: Install node modules run: npm install - name: Publish package diff --git a/.github/workflows/performance_impact.yml b/.github/workflows/performance_impact.yml index a1281964..bd64967c 100644 --- a/.github/workflows/performance_impact.yml +++ b/.github/workflows/performance_impact.yml @@ -28,7 +28,7 @@ jobs: # "setup-node@v3" documentation available at https://github.com/actions/setup-node uses: actions/setup-node@v3 with: - node-version: "20.8.0" + node-version: "22.3.0" - name: Install node modules run: npm install - name: Report performance impact diff --git a/.github/workflows/report_performance_impact.mjs b/.github/workflows/report_performance_impact.mjs index 1a2cac60..1836e135 100644 --- a/.github/workflows/report_performance_impact.mjs +++ b/.github/workflows/report_performance_impact.mjs @@ -6,8 +6,8 @@ */ import { - reportPerformanceImpact, readGitHubWorkflowEnv, + reportPerformanceImpact, } from "@jsenv/performance-impact"; await reportPerformanceImpact({ diff --git a/.gitignore b/.gitignore index 5ec64764..b10e9b76 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,6 @@ .DS_Store +**/git_ignored/ +/todo.txt + diff --git a/.prettierrc.yml b/.prettierrc.yml index f75cac41..1092d542 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,2 +1,4 @@ trailingComma: "all" quoteProps: "consistent" +plugins: ["prettier-plugin-organize-imports"] +organizeImportsSkipDestructiveCodeActions: true diff --git a/experiment/getImportMapFromFile.js b/experiment/getImportMapFromFile.js index e47cbc1b..073ee835 100644 --- a/experiment/getImportMapFromFile.js +++ b/experiment/getImportMapFromFile.js @@ -1,6 +1,6 @@ import { assertAndNormalizeDirectoryUrl, readFile } from "@jsenv/filesystem"; -import { resolveUrl } from "@jsenv/urls"; import { moveImportMap, sortImportMap } from "@jsenv/importmap"; +import { resolveUrl } from "@jsenv/urls"; export const getImportMapFromFile = async ({ projectDirectoryUrl, diff --git a/experiment/lit_typescript/dist/index.js b/experiment/lit_typescript/dist/index.js index eae075b7..c7c38d84 100644 --- a/experiment/lit_typescript/dist/index.js +++ b/experiment/lit_typescript/dist/index.js @@ -1,5 +1,5 @@ /* eslint-disable no-unused-vars */ -import { html, css } from "lit"; +import { css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; console.log({ html: html, diff --git a/experiment/lit_typescript/index.ts b/experiment/lit_typescript/index.ts index 1329c451..ffbe3b9a 100644 --- a/experiment/lit_typescript/index.ts +++ b/experiment/lit_typescript/index.ts @@ -1,6 +1,6 @@ /* eslint-disable no-unused-vars */ -import { html, css } from "lit"; +import { css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; console.log({ html, css, customElement, property }); diff --git a/package.json b/package.json index 47069bc6..95d32b63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/importmap-node-module", - "version": "7.0.0", + "version": "7.0.1", "description": "Generate importmap for node_modules", "license": "MIT", "repository": { @@ -28,41 +28,45 @@ "workspaces": [ "./docs/demo" ], + "volta": { + "node": "22.3.0" + }, "scripts": { "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html", - "performance": "node --expose-gc ./scripts/performance.mjs --log", "test": "node ./scripts/test.mjs", - "prettier": "prettier --write ." + "prettier": "prettier --write .", + "performance": "node --expose-gc ./scripts/performance.mjs --log" }, "dependencies": { - "@babel/core": "7.23.7", - "@babel/traverse": "7.23.7", - "@jsenv/ast": "6.0.1", - "@jsenv/filesystem": "4.6.1", + "@babel/core": "7.24.9", + "@babel/traverse": "7.24.8", + "@jsenv/ast": "6.2.8", + "@jsenv/filesystem": "4.9.4", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", - "@jsenv/urls": "2.2.1" + "@jsenv/urls": "2.4.0" }, "devDependencies": { - "@babel/eslint-parser": "7.23.3", + "@babel/eslint-parser": "7.24.8", "@babel/plugin-proposal-class-properties": "7.18.6", - "@babel/plugin-proposal-decorators": "7.23.7", - "@babel/plugin-syntax-import-assertions": "7.23.3", - "@babel/plugin-syntax-jsx": "7.23.3", - "@jsenv/assert": "2.13.1", + "@babel/plugin-proposal-decorators": "7.24.7", + "@babel/plugin-syntax-import-attributes": "7.24.7", + "@babel/plugin-syntax-jsx": "7.24.7", + "@jsenv/assert": "4.1.6", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "38.3.11", - "@jsenv/eslint-config": "16.4.5", - "@jsenv/github-release-package": "1.5.4", + "@jsenv/core": "39.2.10", + "@jsenv/eslint-config": "16.5.2", + "@jsenv/github-release-package": "1.5.5", "@jsenv/importmap-eslint-resolver": "5.2.5", - "@jsenv/package-publish": "1.10.4", - "@jsenv/performance-impact": "4.2.0", - "@jsenv/server": "15.1.8", - "@jsenv/snapshot": "1.2.0", - "@jsenv/test": "2.1.3", - "eslint": "8.56.0", - "eslint-plugin-html": "7.1.0", + "@jsenv/package-publish": "1.10.5", + "@jsenv/performance-impact": "4.2.1", + "@jsenv/server": "15.2.15", + "@jsenv/snapshot": "2.6.1", + "@jsenv/test": "3.3.20", + "eslint": "8.57.0", + "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", - "prettier": "3.1.1" + "prettier": "3.3.3", + "prettier-plugin-organize-imports": "4.0.0" } } diff --git a/scripts/test.mjs b/scripts/test.mjs index eabcdc10..7e7ef2d7 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -9,6 +9,4 @@ await executeTestPlan({ }, }, }, - logShortForCompletedExecutions: true, - concurrency: true, }); diff --git a/src/cli.mjs b/src/cli.mjs index f6854f22..dae10755 100755 --- a/src/cli.mjs +++ b/src/cli.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node -import { parseArgs } from "node:util"; import { pathToFileURL } from "node:url"; +import { parseArgs } from "node:util"; import { writeImportmaps } from "./main.js"; const options = { diff --git a/src/step_entry_point/html_parser.js b/src/step_entry_point/html_parser.js index 9d994e7e..cacebbf3 100644 --- a/src/step_entry_point/html_parser.js +++ b/src/step_entry_point/html_parser.js @@ -1,13 +1,13 @@ -import { readFile } from "@jsenv/filesystem"; import { - parseHtml, - visitHtmlNodes, - getHtmlNodeAttribute, - getHtmlNodeText, generateUrlForInlineContent, + getHtmlNodeAttribute, getHtmlNodeAttributePosition, getHtmlNodePosition, + getHtmlNodeText, + parseHtml, + visitHtmlNodes, } from "@jsenv/ast"; +import { readFile } from "@jsenv/filesystem"; export const parseHTMLRessources = async ({ code, url, asFileUrl }) => { const htmlAst = parseHtml({ html: code, url, storeOriginalPositions: false }); diff --git a/src/step_entry_point/js_parser.js b/src/step_entry_point/js_parser.js index 9983f80a..b2ef735d 100644 --- a/src/step_entry_point/js_parser.js +++ b/src/step_entry_point/js_parser.js @@ -1,6 +1,6 @@ -import { createRequire } from "node:module"; import { parseAsync } from "@babel/core"; import { urlToFileSystemPath } from "@jsenv/urls"; +import { createRequire } from "node:module"; const require = createRequire(import.meta.url); diff --git a/src/step_entry_point/test_importmap_on_entry_points.js b/src/step_entry_point/test_importmap_on_entry_points.js index af467443..7e2ab9e5 100644 --- a/src/step_entry_point/test_importmap_on_entry_points.js +++ b/src/step_entry_point/test_importmap_on_entry_points.js @@ -1,31 +1,31 @@ import { loadOptionsAsync } from "@babel/core"; import { readFile } from "@jsenv/filesystem"; import { - resolveUrl, - urlToExtension, - urlToRelativeUrl, - urlIsInsideOf, - urlToFileSystemPath, -} from "@jsenv/urls"; -import { + composeTwoImportMaps, normalizeImportMap, resolveImport, - composeTwoImportMaps, } from "@jsenv/importmap"; import { isSpecifierForNodeCoreModule } from "@jsenv/importmap/src/isSpecifierForNodeCoreModule.js"; - import { - memoizeAsyncFunctionByUrl, - memoizeAsyncFunctionBySpecifierAndImporter, -} from "../util/memoize_async_function.js"; -import { resolveFile } from "../util/resolve_file.js"; + resolveUrl, + urlIsInsideOf, + urlToExtension, + urlToFileSystemPath, + urlToRelativeUrl, +} from "@jsenv/urls"; + import { createBareSpecifierAutomappingMessage, createExtensionAutomappingMessage, createImportResolutionFailedWarning, } from "../util/logs.js"; -import { parseSpecifiersFromJs } from "./js_parser.js"; +import { + memoizeAsyncFunctionBySpecifierAndImporter, + memoizeAsyncFunctionByUrl, +} from "../util/memoize_async_function.js"; +import { resolveFile } from "../util/resolve_file.js"; import { parseHTMLRessources } from "./html_parser.js"; +import { parseSpecifiersFromJs } from "./js_parser.js"; import { showSource } from "./show_source.js"; export const testImportmapOnEntryPoints = async ( diff --git a/src/step_node_esm/node_module_resolution.js b/src/step_node_esm/node_module_resolution.js index ad13de18..d0de36b6 100644 --- a/src/step_node_esm/node_module_resolution.js +++ b/src/step_node_esm/node_module_resolution.js @@ -1,13 +1,13 @@ -import { readFile, ensureWindowsDriveLetter } from "@jsenv/filesystem"; +import { ensureWindowsDriveLetter, readFile } from "@jsenv/filesystem"; import { - urlToRelativeUrl, resolveUrl, - urlToParentUrl, urlToFileSystemPath, + urlToParentUrl, + urlToRelativeUrl, } from "@jsenv/urls"; -import { memoizeAsyncFunctionByUrl } from "../util/memoize_async_function.js"; import { findAsync } from "../util/find_async.js"; +import { memoizeAsyncFunctionByUrl } from "../util/memoize_async_function.js"; export const createFindNodeModulePackage = () => { const readPackageFileMemoized = memoizeAsyncFunctionByUrl( diff --git a/src/step_node_esm/resolve_package_main.js b/src/step_node_esm/resolve_package_main.js index 845dbd17..05cc6c26 100644 --- a/src/step_node_esm/resolve_package_main.js +++ b/src/step_node_esm/resolve_package_main.js @@ -2,8 +2,8 @@ import { createDetailedMessage } from "@jsenv/logger"; import { resolveUrl, urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"; import { - createPreferExportsFieldWarning, createBrowserFieldNotImplementedWarning, + createPreferExportsFieldWarning, } from "../util/logs.js"; import { resolveFile } from "../util/resolve_file.js"; diff --git a/src/step_node_esm/visit_node_module_resolution.js b/src/step_node_esm/visit_node_module_resolution.js index 290480e1..efcbff12 100644 --- a/src/step_node_esm/visit_node_module_resolution.js +++ b/src/step_node_esm/visit_node_module_resolution.js @@ -1,12 +1,12 @@ -import { readFileSync } from "node:fs"; import { createDetailedMessage } from "@jsenv/logger"; -import { urlToRelativeUrl, urlToFileSystemPath } from "@jsenv/urls"; +import { urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"; +import { readFileSync } from "node:fs"; +import { createFindNodeModulePackage } from "./node_module_resolution.js"; import { resolvePackageMain } from "./resolve_package_main.js"; +import { visitPackageExports } from "./visit_package_exports.js"; import { visitPackageImportmap } from "./visit_package_importmap.js"; import { visitPackageImports } from "./visit_package_imports.js"; -import { visitPackageExports } from "./visit_package_exports.js"; -import { createFindNodeModulePackage } from "./node_module_resolution.js"; export const visitNodeModuleResolution = async ( visitors, diff --git a/src/step_node_esm/visit_package_exports.js b/src/step_node_esm/visit_package_exports.js index 1ee66391..9aa02d4d 100644 --- a/src/step_node_esm/visit_package_exports.js +++ b/src/step_node_esm/visit_package_exports.js @@ -4,8 +4,8 @@ https://nodejs.org/docs/latest-v15.x/api/packages.html#packages_node_js_package_ */ -import { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from "@jsenv/urls"; import { createDetailedMessage } from "@jsenv/logger"; +import { resolveUrl, urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"; import { specifierIsRelative } from "./specifier_is_relative.js"; diff --git a/src/step_node_esm/visit_package_importmap.js b/src/step_node_esm/visit_package_importmap.js index 06fc1979..20ab8f54 100644 --- a/src/step_node_esm/visit_package_importmap.js +++ b/src/step_node_esm/visit_package_importmap.js @@ -1,5 +1,5 @@ -import { resolveUrl, moveImportMap } from "@jsenv/importmap"; import { readFile } from "@jsenv/filesystem"; +import { moveImportMap, resolveUrl } from "@jsenv/importmap"; import { urlToFileSystemPath } from "@jsenv/urls"; export const visitPackageImportmap = async ({ diff --git a/src/step_write_into_files/write_into_files.js b/src/step_write_into_files/write_into_files.js index e22619e0..be08facf 100644 --- a/src/step_write_into_files/write_into_files.js +++ b/src/step_write_into_files/write_into_files.js @@ -1,15 +1,15 @@ -import { readFileSync, writeFileSync } from "@jsenv/filesystem"; -import { urlToFileSystemPath } from "@jsenv/urls"; import { - parseHtml, + createHtmlNode, findHtmlNode, getHtmlNodeAttribute, + injectHtmlNodeAsEarlyAsPossible, + parseHtml, setHtmlNodeAttributes, setHtmlNodeText, - createHtmlNode, - injectHtmlNodeAsEarlyAsPossible, stringifyHtmlAst, } from "@jsenv/ast"; +import { readFileSync, writeFileSync } from "@jsenv/filesystem"; +import { urlToFileSystemPath } from "@jsenv/urls"; export const writeIntoFiles = ( importmapInfos, @@ -64,7 +64,7 @@ const writeIntoHtmlFile = (htmlFileUrl, importmapAsJson, { logger }) => { const importmapNode = createHtmlNode({ tagName: "script", type: "importmap", - textContent: importmapAsJson, + children: importmapAsJson, }); injectHtmlNodeAsEarlyAsPossible(htmlAst, importmapNode); setHtmlNodeAttributes(importmapNode, { diff --git a/src/util/logs.js b/src/util/logs.js index 063a90da..500be58d 100644 --- a/src/util/logs.js +++ b/src/util/logs.js @@ -1,5 +1,5 @@ import { createDetailedMessage } from "@jsenv/logger"; -import { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from "@jsenv/urls"; +import { resolveUrl, urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"; export const createPreferExportsFieldWarning = ({ packageInfo, diff --git a/src/util/memoize_async_function.js b/src/util/memoize_async_function.js index 90123b59..cb3d5f8e 100644 --- a/src/util/memoize_async_function.js +++ b/src/util/memoize_async_function.js @@ -50,7 +50,7 @@ export const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => { }; const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { - const memoized = async (...args) => { + const memoized = (...args) => { const memoryEntry = getMemoryEntryFromArguments(args); const promiseFromMemory = memoryEntry.get(); if (promiseFromMemory) { diff --git a/src/write_importmaps.js b/src/write_importmaps.js index a1bedd5b..daf499cd 100644 --- a/src/write_importmaps.js +++ b/src/write_importmaps.js @@ -1,14 +1,14 @@ -import { createLogger } from "@jsenv/logger"; import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"; import { composeTwoImportMaps, - sortImportMap, moveImportMap, + sortImportMap, } from "@jsenv/importmap"; +import { createLogger } from "@jsenv/logger"; -import { generateImportmapForNodeESMResolution } from "./step_node_esm/importmap_for_node_esm.js"; import { testImportmapOnEntryPoints } from "./step_entry_point/test_importmap_on_entry_points.js"; import { updateJsConfigForVsCode } from "./step_jsconfig/update_js_config_for_vscode.js"; +import { generateImportmapForNodeESMResolution } from "./step_node_esm/importmap_for_node_esm.js"; import { writeIntoFiles } from "./step_write_into_files/write_into_files.js"; const importResolutionDefault = { @@ -54,7 +54,7 @@ export const writeImportmaps = async ({ const logger = createLogger({ logLevel }); const warn = wrapWarnToWarnOnce((warning) => { onWarn(warning, () => { - logger.warn(`\n${warning.message}\n`); + console.warn(`\n${warning.message}\n`); }); }); diff --git a/tests/__internal__/import_map_to_vs_code_config_paths.test.mjs b/tests/__internal__/import_map_to_vs_code_config_paths.test.mjs index 02dd3805..25b9b705 100644 --- a/tests/__internal__/import_map_to_vs_code_config_paths.test.mjs +++ b/tests/__internal__/import_map_to_vs_code_config_paths.test.mjs @@ -9,9 +9,9 @@ import { importmapToVsCodeConfigPaths } from "@jsenv/importmap-node-module/src/s "foo/": "./node_modules/foo/", }, }); - const expected = { + const expect = { "foo": ["./node_modules/foo/index.js"], "foo/*": ["./node_modules/foo/*"], }; - assert({ actual, expected }); + assert({ actual, expect }); } diff --git a/tests/__internal__/js_parser.test.mjs b/tests/__internal__/js_parser.test.mjs index fc9dbcc4..5060a3ae 100644 --- a/tests/__internal__/js_parser.test.mjs +++ b/tests/__internal__/js_parser.test.mjs @@ -1,5 +1,5 @@ -import { writeFile, ensureEmptyDirectory, readFile } from "@jsenv/filesystem"; import { assert } from "@jsenv/assert"; +import { ensureEmptyDirectory, readFile, writeFile } from "@jsenv/filesystem"; import { parseSpecifiersFromJs } from "@jsenv/importmap-node-module/src/step_entry_point/js_parser.js"; @@ -19,7 +19,7 @@ import "./bar.js" url: fileUrl, }); const actual = specifiers; - const expected = { + const expect = { "./foo": { line: 1, column: 7, @@ -31,7 +31,7 @@ import "./bar.js" type: "import-static", }, }; - assert({ actual, expected }); + assert({ actual, expect }); await ensureEmptyDirectory(testDirectoryUrl); } @@ -48,14 +48,14 @@ import(id) url: fileUrl, }); const actual = specifiers; - const expected = { + const expect = { "./foo": { line: 1, column: 7, type: "import-dynamic", }, }; - assert({ actual, expected }); + assert({ actual, expect }); await ensureEmptyDirectory(testDirectoryUrl); } @@ -67,14 +67,14 @@ import(id) url: fileUrl, }); const actual = specifiers; - const expected = { + const expect = { "./foo": { line: 1, column: 19, type: "export-named", }, }; - assert({ actual, expected }); + assert({ actual, expect }); await ensureEmptyDirectory(testDirectoryUrl); } @@ -86,13 +86,13 @@ import(id) url: fileUrl, }); const actual = specifiers; - const expected = { + const expect = { "./foo": { line: 1, column: 14, type: "export-all", }, }; - assert({ actual, expected }); + assert({ actual, expect }); await ensureEmptyDirectory(testDirectoryUrl); } diff --git a/tests/__internal__/updating_jsconfig/updating_jsconfig_react.test.mjs b/tests/__internal__/updating_jsconfig/updating_jsconfig_react.test.mjs index 20d61e41..34ddd23f 100644 --- a/tests/__internal__/updating_jsconfig/updating_jsconfig_react.test.mjs +++ b/tests/__internal__/updating_jsconfig/updating_jsconfig_react.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { copyFileSync } from "@jsenv/filesystem"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/auto_mapping_bare_specifier.test.mjs b/tests/entry_point_check/auto_mapping_bare_specifier/auto_mapping_bare_specifier.test.mjs index 5b5f182f..e8556631 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/auto_mapping_bare_specifier.test.mjs +++ b/tests/entry_point_check/auto_mapping_bare_specifier/auto_mapping_bare_specifier.test.mjs @@ -1,67 +1,29 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { assert } from "@jsenv/assert"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const test = async ({ bareSpecifierAutomapping }) => { - const importmapRelativeUrl = bareSpecifierAutomapping - ? "test_base_automapping.importmap" - : "test.importmap"; - const importmapFileUrl = new URL( - `./root/${importmapRelativeUrl}`, +const test = async (scenario, { bareSpecifierAutomapping }) => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + [`${scenario}.importmap`]: { + importResolution: { + entryPoints: ["./index.js"], + bareSpecifierAutomapping, + }, + }, + }, + }), import.meta.url, + `./output/${scenario}.md`, ); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - [importmapRelativeUrl]: { - importResolution: { - entryPoints: ["./index.js"], - bareSpecifierAutomapping, - }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - importmapFileSnapshot.compare(); - const actual = warnings; - const expected = bareSpecifierAutomapping - ? [] - : [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "file" ---- import trace --- -${testDirectoryUrl}index.js:2:7 - 1 | // eslint-disable-next-line import/no-unresolved -> 2 | import "file"; - | ^ - 3 |${" "} ---- reason --- -there is no mapping for this bare specifier ---- suggestion 1 --- -update import specifier to "./file.js" ---- suggestion 2 --- -use bareSpecifierAutomapping: true ---- suggestion 3 --- -add mapping to "manualImportmap" -{ - "imports": { - "file": "./file.js" - } -}`, - }, - ]; - assert({ actual, expected }); - - return { warnings }; }; -await test({}); -await test({ bareSpecifierAutomapping: true }); +await test("0_bare_specifier_warning", { + bareSpecifierAutomapping: undefined, +}); +await test("1_bare_specifier_automapping", { + bareSpecifierAutomapping: true, +}); diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/root/file.js b/tests/entry_point_check/auto_mapping_bare_specifier/input/file.js similarity index 100% rename from tests/entry_point_check/auto_mapping_bare_specifier/root/file.js rename to tests/entry_point_check/auto_mapping_bare_specifier/input/file.js diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/root/index.js b/tests/entry_point_check/auto_mapping_bare_specifier/input/index.js similarity index 100% rename from tests/entry_point_check/auto_mapping_bare_specifier/root/index.js rename to tests/entry_point_check/auto_mapping_bare_specifier/input/index.js diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/root/package.json b/tests/entry_point_check/auto_mapping_bare_specifier/input/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_bare_specifier/root/package.json rename to tests/entry_point_check/auto_mapping_bare_specifier/input/package.json diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md new file mode 100644 index 00000000..34bf33a9 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md @@ -0,0 +1,45 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "file" +--- import trace --- +file:////input/index.js:2:7 + 1 | // eslint-disable-next-line import/no-unresolved +> 2 | import "file"; + | ^ + 3 | +--- reason --- +there is no mapping for this bare specifier +--- suggestion 1 --- +update import specifier to "./file.js" +--- suggestion 2 --- +use bareSpecifierAutomapping: true +--- suggestion 3 --- +add mapping to "manualImportmap" +{ + "imports": { + "file": "./file.js" + } +} + +``` + +3. write file "input/0_bare_specifier_warning.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +4. resolve +```js +{ + "0_bare_specifier_warning.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping.md b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping.md new file mode 100644 index 00000000..48096139 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/1_bare_specifier_automapping.importmap" +```importmap +{ + "imports": { + "file": "./file.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "1_bare_specifier_automapping.importmap": { + "imports": { + "file": "./file.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/root/test.importmap b/tests/entry_point_check/auto_mapping_bare_specifier/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/auto_mapping_bare_specifier/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/root/test_base_automapping.importmap b/tests/entry_point_check/auto_mapping_bare_specifier/root/test_base_automapping.importmap deleted file mode 100644 index f4e664a1..00000000 --- a/tests/entry_point_check/auto_mapping_bare_specifier/root/test_base_automapping.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "file": "./file.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_css_to_js/auto_mapping_css_to_js.test.mjs b/tests/entry_point_check/auto_mapping_css_to_js/auto_mapping_css_to_js.test.mjs index 0bbc2a6e..e5ce8576 100644 --- a/tests/entry_point_check/auto_mapping_css_to_js/auto_mapping_css_to_js.test.mjs +++ b/tests/entry_point_check/auto_mapping_css_to_js/auto_mapping_css_to_js.test.mjs @@ -1,20 +1,23 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL(`./root/test.importmap`, import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./main.js"], - magicExtensions: ["inherit"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); +const test = async () => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + magicExtensions: ["inherit"], + }, + }, + }, + }), + import.meta.url, + `./output/auto_mapping_css_to_js.md`, + ); +}; +await test(); diff --git a/tests/entry_point_check/auto_mapping_css_to_js/root/file.css.js b/tests/entry_point_check/auto_mapping_css_to_js/input/file.css.js similarity index 100% rename from tests/entry_point_check/auto_mapping_css_to_js/root/file.css.js rename to tests/entry_point_check/auto_mapping_css_to_js/input/file.css.js diff --git a/tests/entry_point_check/auto_mapping_css_to_js/root/main.js b/tests/entry_point_check/auto_mapping_css_to_js/input/main.js similarity index 100% rename from tests/entry_point_check/auto_mapping_css_to_js/root/main.js rename to tests/entry_point_check/auto_mapping_css_to_js/input/main.js diff --git a/tests/entry_point_check/auto_mapping_css_to_js/root/package.json b/tests/entry_point_check/auto_mapping_css_to_js/input/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_css_to_js/root/package.json rename to tests/entry_point_check/auto_mapping_css_to_js/input/package.json diff --git a/tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md b/tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md new file mode 100644 index 00000000..6a27c8c1 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "./file.css": "./file.css.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "./file.css": "./file.css.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_css_to_js/root/test.importmap b/tests/entry_point_check/auto_mapping_css_to_js/root/test.importmap deleted file mode 100644 index 005ea1bb..00000000 --- a/tests/entry_point_check/auto_mapping_css_to_js/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "./file.css": "./file.css.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/auto_mapping_extensionless_in_node_module.test.mjs b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/auto_mapping_extensionless_in_node_module.test.mjs index f47a4353..1e4c7d4b 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/auto_mapping_extensionless_in_node_module.test.mjs +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/auto_mapping_extensionless_in_node_module.test.mjs @@ -1,92 +1,32 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { assert } from "@jsenv/assert"; -import { urlToFileSystemPath } from "@jsenv/urls"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); - -const test = async ({ name, magicExtensions, expectedWarnings }) => { - const importmapRelativeUrl = `${name}.importmap`; - const importmapFileUrl = new URL( - `./root/${importmapRelativeUrl}`, +const test = async (scenario, { magicExtensions } = {}) => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + magicExtensions, + }, + }, + }, + }), import.meta.url, + `./output/${scenario}.md`, ); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - [importmapRelativeUrl]: { - importResolution: { - entryPoints: ["./main.js"], - magicExtensions, - }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - importmapFileSnapshot.compare(); - const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); }; -await test({ - name: "default", - expectedWarnings: [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "./file" ---- import trace --- -${testDirectoryUrl}node_modules/leftpad/index.js:1:7 -> 1 | import "./file" - | ^ ---- reason --- -file not found on filesystem at ${urlToFileSystemPath( - `${testDirectoryUrl}node_modules/leftpad/file`, - )} ---- suggestion 1 --- -update import specifier to "./file.js" ---- suggestion 2 --- -use magicExtensions: ["inherit"] ---- suggestion 3 --- -add mapping to "manualImportmap" -{ - "scopes": { - "./node_modules/leftpad/": { - "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" - } - } -}`, - }, - ], +await test("0_magic_extensions_warning", { + magicExtensions: undefined, }); - -await test({ - name: "magic_extensions_js", +await test("1_magic_extensions_js", { magicExtensions: [".js"], - expectedWarnings: [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "./other-file" ---- import trace --- -${testDirectoryUrl}node_modules/leftpad/file.js:1:7 -> 1 | import "./other-file" - | ^ ---- reason --- -file not found on filesystem at ${urlToFileSystemPath( - `${testDirectoryUrl}node_modules/leftpad/other-file`, - )}`, - }, - ], }); - -await test({ - name: "magic_extensions_inherit", +await test("2_magic_extensions_inherit", { magicExtensions: ["inherit", ".ts"], - expectedWarnings: [], }); diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/main.js b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/main.js similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/main.js rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/main.js diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/file.js b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/file.js similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/file.js rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/file.js diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/index.js b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/index.js similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/index.js rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/index.js diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/other-file.ts b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/other-file.ts similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/other-file.ts rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/other-file.ts diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/package.json b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/node_modules/leftpad/package.json rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/node_modules/leftpad/package.json diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/package.json b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/package.json rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/input/package.json diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md new file mode 100644 index 00000000..b092b7ca --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md @@ -0,0 +1,49 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "./file" +--- import trace --- +file:////input/node_modules/leftpad/index.js:1:7 +> 1 | import "./file" + | ^ +--- reason --- +file not found on filesystem at /input/node_modules/leftpad/file +--- suggestion 1 --- +update import specifier to "./file.js" +--- suggestion 2 --- +use magicExtensions: ["inherit"] +--- suggestion 3 --- +add mapping to "manualImportmap" +{ + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } +} + +``` + +3. write file "input/test.importmap" +```importmap +{ + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": {} +} +``` + +4. resolve +```js +{ + "test.importmap": { + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md new file mode 100644 index 00000000..79fdfe98 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md @@ -0,0 +1,44 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "./other-file" +--- import trace --- +file:////input/node_modules/leftpad/file.js:1:7 +> 1 | import "./other-file" + | ^ +--- reason --- +file not found on filesystem at /input/node_modules/leftpad/other-file + +``` + +3. write file "input/test.importmap" +```importmap +{ + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } +} +``` + +4. resolve +```js +{ + "test.importmap": { + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md new file mode 100644 index 00000000..6fca02de --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md @@ -0,0 +1,33 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/other-file": "./node_modules/leftpad/other-file.ts", + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/other-file": "./node_modules/leftpad/other-file.ts", + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/default.importmap b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/default.importmap deleted file mode 100644 index 7ef5f98d..00000000 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/default.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "leftpad": "./node_modules/leftpad/index.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_inherit.importmap b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_inherit.importmap deleted file mode 100644 index 4f5b2f23..00000000 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_inherit.importmap +++ /dev/null @@ -1,11 +0,0 @@ -{ - "imports": { - "leftpad": "./node_modules/leftpad/index.js" - }, - "scopes": { - "./node_modules/leftpad/": { - "./node_modules/leftpad/other-file": "./node_modules/leftpad/other-file.ts", - "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" - } - } -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_js.importmap b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_js.importmap deleted file mode 100644 index 6ad48882..00000000 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_js.importmap +++ /dev/null @@ -1,10 +0,0 @@ -{ - "imports": { - "leftpad": "./node_modules/leftpad/index.js" - }, - "scopes": { - "./node_modules/leftpad/": { - "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" - } - } -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_lodash/auto_mapping_lodash.test.mjs b/tests/entry_point_check/auto_mapping_lodash/auto_mapping_lodash.test.mjs index 2004c6a9..66bc0cae 100644 --- a/tests/entry_point_check/auto_mapping_lodash/auto_mapping_lodash.test.mjs +++ b/tests/entry_point_check/auto_mapping_lodash/auto_mapping_lodash.test.mjs @@ -1,70 +1,29 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { assert } from "@jsenv/assert"; -import { urlToFileSystemPath } from "@jsenv/urls"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const test = async ({ name, magicExtensions, expectedWarnings } = {}) => { - const importmapRelativeUrl = `${name}.importmap`; - const importmapFileUrl = new URL( - `./root/${importmapRelativeUrl}`, +const test = async (scenario, { magicExtensions }) => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + magicExtensions, + }, + }, + }, + }), import.meta.url, + `./output/${scenario}.md`, ); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - packagesManualOverrides: { - lodash: { - exports: { - "./*": "./*", - }, - }, - }, - importmaps: { - [importmapRelativeUrl]: { - importResolution: { - entryPoints: ["./main.js"], - magicExtensions, - }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - importmapFileSnapshot.compare(); - assert({ - actual: warnings, - expected: expectedWarnings, - }); }; -await test({ - name: "magic_extensions_ts", +await test("0_magic_extensions_ts", { magicExtensions: [".ts"], - expectedWarnings: [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "lodash/union" ---- import trace --- -${testDirectoryUrl}main.js:2:22 - 1 | // eslint-disable-next-line import/no-unresolved -> 2 | import { union } from "lodash/union"; - | ^ - 3 | ---- reason --- -file not found on filesystem at ${urlToFileSystemPath( - `${testDirectoryUrl}node_modules/lodash/union`, - )}`, - }, - ], }); - -await test({ - name: "magic_extensions_js", +await test("1_magic_extensions_js", { magicExtensions: [".js"], - expectedWarnings: [], }); diff --git a/tests/entry_point_check/auto_mapping_lodash/root/main.js b/tests/entry_point_check/auto_mapping_lodash/input/main.js similarity index 100% rename from tests/entry_point_check/auto_mapping_lodash/root/main.js rename to tests/entry_point_check/auto_mapping_lodash/input/main.js diff --git a/tests/entry_point_check/auto_mapping_lodash/root/node_modules/lodash/package.json b/tests/entry_point_check/auto_mapping_lodash/input/node_modules/lodash/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_lodash/root/node_modules/lodash/package.json rename to tests/entry_point_check/auto_mapping_lodash/input/node_modules/lodash/package.json diff --git a/tests/entry_point_check/auto_mapping_lodash/root/node_modules/lodash/union.js b/tests/entry_point_check/auto_mapping_lodash/input/node_modules/lodash/union.js similarity index 100% rename from tests/entry_point_check/auto_mapping_lodash/root/node_modules/lodash/union.js rename to tests/entry_point_check/auto_mapping_lodash/input/node_modules/lodash/union.js diff --git a/tests/entry_point_check/auto_mapping_lodash/root/package.json b/tests/entry_point_check/auto_mapping_lodash/input/package.json similarity index 100% rename from tests/entry_point_check/auto_mapping_lodash/root/package.json rename to tests/entry_point_check/auto_mapping_lodash/input/package.json diff --git a/tests/entry_point_check/auto_mapping_lodash/output/0_magic_extensions_ts.md b/tests/entry_point_check/auto_mapping_lodash/output/0_magic_extensions_ts.md new file mode 100644 index 00000000..a53ff40d --- /dev/null +++ b/tests/entry_point_check/auto_mapping_lodash/output/0_magic_extensions_ts.md @@ -0,0 +1,38 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "lodash/union" +--- import trace --- +file:////input/main.js:2:22 + 1 | // eslint-disable-next-line import/no-unresolved +> 2 | import { union } from "lodash/union"; + | ^ + 3 | +--- reason --- +file not found on filesystem at /input/node_modules/lodash/union + +``` + +3. write file "input/test.importmap" +```importmap +{ + "imports": { + "lodash/": "./node_modules/lodash/" + }, + "scopes": {} +} +``` + +4. resolve +```js +{ + "test.importmap": { + "imports": { + "lodash/": "./node_modules/lodash/" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_lodash/output/1_magic_extensions_js.md b/tests/entry_point_check/auto_mapping_lodash/output/1_magic_extensions_js.md new file mode 100644 index 00000000..f8d3a35b --- /dev/null +++ b/tests/entry_point_check/auto_mapping_lodash/output/1_magic_extensions_js.md @@ -0,0 +1,25 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "lodash/union": "./node_modules/lodash/union.js", + "lodash/": "./node_modules/lodash/" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "lodash/union": "./node_modules/lodash/union.js", + "lodash/": "./node_modules/lodash/" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_js.importmap b/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_js.importmap deleted file mode 100644 index 5fc1742a..00000000 --- a/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_js.importmap +++ /dev/null @@ -1,7 +0,0 @@ -{ - "imports": { - "lodash/union": "./node_modules/lodash/union.js", - "lodash/": "./node_modules/lodash/" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_ts.importmap b/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_ts.importmap deleted file mode 100644 index 7a0a25a9..00000000 --- a/tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_ts.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "lodash/": "./node_modules/lodash/" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_file_not_found/entry_point_file_not_found.test.mjs b/tests/entry_point_check/entry_point_file_not_found/entry_point_file_not_found.test.mjs index a2ce89ab..cadc1718 100644 --- a/tests/entry_point_check/entry_point_file_not_found/entry_point_file_not_found.test.mjs +++ b/tests/entry_point_check/entry_point_file_not_found/entry_point_file_not_found.test.mjs @@ -1,51 +1,29 @@ -import { assert } from "@jsenv/assert"; -import { writeFileSync, removeFileSync } from "@jsenv/filesystem"; -import { urlToFileSystemPath } from "@jsenv/urls"; - +import { writeFileStructureSync } from "@jsenv/filesystem"; import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const mainJsFileUrl = new URL("./main.js", testDirectoryUrl); -const getWarnings = async () => { - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./main.js"], +const test = async (scenario) => { + writeFileStructureSync( + new URL("./git_ignored/", import.meta.url), + new URL(`./fixtures/${scenario}/`, import.meta.url), + ); + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./git_ignored/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + }, + }, }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - return warnings; + }), + import.meta.url, + `./output/${scenario}.md`, + ); }; -removeFileSync(mainJsFileUrl, { allowUseless: true }); -{ - const actual = await getWarnings(); - const expected = [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "./main.js" ---- import trace --- -entryPoints parameter ---- reason --- -file not found on filesystem at ${urlToFileSystemPath( - `${testDirectoryUrl}main.js`, - )}`, - }, - ]; - assert({ actual, expected }); -} - -writeFileSync(mainJsFileUrl); -{ - const actual = await getWarnings(); - const expected = []; - assert({ actual, expected }); -} +await test("0_not_found"); +await test("1_found"); diff --git a/tests/entry_point_check/entry_point_file_not_found/root/package.json b/tests/entry_point_check/entry_point_file_not_found/fixtures/0_not_found/package.json similarity index 100% rename from tests/entry_point_check/entry_point_file_not_found/root/package.json rename to tests/entry_point_check/entry_point_file_not_found/fixtures/0_not_found/package.json diff --git a/tests/entry_point_check/entry_point_file_not_found/root/main.js b/tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/main.js similarity index 100% rename from tests/entry_point_check/entry_point_file_not_found/root/main.js rename to tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/main.js diff --git a/tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/package.json b/tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/package.json new file mode 100644 index 00000000..115f83ce --- /dev/null +++ b/tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/package.json @@ -0,0 +1,9 @@ +{ + "name": "root", + "exports": { + ".": { + "require": "./main.cjs", + "import": "./main.js" + } + } +} diff --git a/tests/entry_point_check/entry_point_file_not_found/output/0_not_found.md b/tests/entry_point_check/entry_point_file_not_found/output/0_not_found.md new file mode 100644 index 00000000..e2641c75 --- /dev/null +++ b/tests/entry_point_check/entry_point_file_not_found/output/0_not_found.md @@ -0,0 +1,30 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "./main.js" +--- import trace --- +entryPoints parameter +--- reason --- +file not found on filesystem at /git_ignored/main.js + +``` + +3. write file "git_ignored/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +4. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_file_not_found/output/1_found.md b/tests/entry_point_check/entry_point_file_not_found/output/1_found.md new file mode 100644 index 00000000..4a3ad3e9 --- /dev/null +++ b/tests/entry_point_check/entry_point_file_not_found/output/1_found.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "git_ignored/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_file_not_found/root/test.importmap b/tests/entry_point_check/entry_point_file_not_found/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/entry_point_file_not_found/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_html_script_module/entry_point_html_script_module.test.mjs b/tests/entry_point_check/entry_point_html_script_module/entry_point_html_script_module.test.mjs index 71cf4e99..4b121417 100644 --- a/tests/entry_point_check/entry_point_html_script_module/entry_point_html_script_module.test.mjs +++ b/tests/entry_point_check/entry_point_html_script_module/entry_point_html_script_module.test.mjs @@ -1,29 +1,29 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - manualImportmap: { - imports: { - a: "./a.js", - b: "./b.js", - inline_everything: "./everything.js", - a_everything: "./everything.js", - b_everything: "./everything.js", - c_everything: "./everything.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + manualImportmap: { + imports: { + a: "./a.js", + b: "./b.js", + inline_everything: "./everything.js", + a_everything: "./everything.js", + b_everything: "./everything.js", + c_everything: "./everything.js", + }, + }, + importResolution: { + entryPoints: ["./main.html"], + }, }, }, - importResolution: { - entryPoints: ["./main.html"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/entry_point_html_script_module.md`, +); diff --git a/tests/entry_point_check/entry_point_html_script_module/root/a.js b/tests/entry_point_check/entry_point_html_script_module/input/a.js similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/a.js rename to tests/entry_point_check/entry_point_html_script_module/input/a.js diff --git a/tests/entry_point_check/entry_point_html_script_module/root/b.js b/tests/entry_point_check/entry_point_html_script_module/input/b.js similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/b.js rename to tests/entry_point_check/entry_point_html_script_module/input/b.js diff --git a/tests/entry_point_check/entry_point_html_script_module/root/c.js b/tests/entry_point_check/entry_point_html_script_module/input/c.js similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/c.js rename to tests/entry_point_check/entry_point_html_script_module/input/c.js diff --git a/tests/entry_point_check/entry_point_html_script_module/root/everything.js b/tests/entry_point_check/entry_point_html_script_module/input/everything.js similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/everything.js rename to tests/entry_point_check/entry_point_html_script_module/input/everything.js diff --git a/tests/entry_point_check/entry_point_html_script_module/root/main.html b/tests/entry_point_check/entry_point_html_script_module/input/main.html similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/main.html rename to tests/entry_point_check/entry_point_html_script_module/input/main.html diff --git a/tests/entry_point_check/entry_point_html_script_module/root/package.json b/tests/entry_point_check/entry_point_html_script_module/input/package.json similarity index 100% rename from tests/entry_point_check/entry_point_html_script_module/root/package.json rename to tests/entry_point_check/entry_point_html_script_module/input/package.json diff --git a/tests/entry_point_check/entry_point_html_script_module/output/entry_point_html_script_module.md b/tests/entry_point_check/entry_point_html_script_module/output/entry_point_html_script_module.md new file mode 100644 index 00000000..14d05411 --- /dev/null +++ b/tests/entry_point_check/entry_point_html_script_module/output/entry_point_html_script_module.md @@ -0,0 +1,31 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "inline_everything": "./everything.js", + "a_everything": "./everything.js", + "b_everything": "./everything.js", + "c_everything": "./everything.js", + "a": "./a.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "inline_everything": "./everything.js", + "a_everything": "./everything.js", + "b_everything": "./everything.js", + "c_everything": "./everything.js", + "a": "./a.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_html_script_module/root/test.importmap b/tests/entry_point_check/entry_point_html_script_module/root/test.importmap deleted file mode 100644 index 07e18468..00000000 --- a/tests/entry_point_check/entry_point_html_script_module/root/test.importmap +++ /dev/null @@ -1,10 +0,0 @@ -{ - "imports": { - "inline_everything": "./everything.js", - "a_everything": "./everything.js", - "b_everything": "./everything.js", - "c_everything": "./everything.js", - "a": "./a.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_many/entry_point_many.test.mjs b/tests/entry_point_check/entry_point_many/entry_point_many.test.mjs index 0fa7c175..d0110036 100644 --- a/tests/entry_point_check/entry_point_many/entry_point_many.test.mjs +++ b/tests/entry_point_check/entry_point_many/entry_point_many.test.mjs @@ -1,24 +1,24 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - manualImportmap: { - imports: { - "root/": "./", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + manualImportmap: { + imports: { + "root/": "./", + }, + }, + importResolution: { + entryPoints: ["./first/first.js", "second/second.js"], + }, }, }, - importResolution: { - entryPoints: ["./first/first.js", "second/second.js"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/entry_point_html_script_module.md`, +); diff --git a/tests/entry_point_check/entry_point_many/root/common.js b/tests/entry_point_check/entry_point_many/input/common.js similarity index 100% rename from tests/entry_point_check/entry_point_many/root/common.js rename to tests/entry_point_check/entry_point_many/input/common.js diff --git a/tests/entry_point_check/entry_point_many/root/first/first.js b/tests/entry_point_check/entry_point_many/input/first/first.js similarity index 100% rename from tests/entry_point_check/entry_point_many/root/first/first.js rename to tests/entry_point_check/entry_point_many/input/first/first.js diff --git a/tests/entry_point_check/entry_point_many/root/package.json b/tests/entry_point_check/entry_point_many/input/package.json similarity index 100% rename from tests/entry_point_check/entry_point_many/root/package.json rename to tests/entry_point_check/entry_point_many/input/package.json diff --git a/tests/entry_point_check/entry_point_many/root/second/second.js b/tests/entry_point_check/entry_point_many/input/second/second.js similarity index 100% rename from tests/entry_point_check/entry_point_many/root/second/second.js rename to tests/entry_point_check/entry_point_many/input/second/second.js diff --git a/tests/entry_point_check/entry_point_many/output/entry_point_html_script_module.md b/tests/entry_point_check/entry_point_many/output/entry_point_html_script_module.md new file mode 100644 index 00000000..be4e1277 --- /dev/null +++ b/tests/entry_point_check/entry_point_many/output/entry_point_html_script_module.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "root/": "./" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "root/": "./" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_many/root/test.importmap b/tests/entry_point_check/entry_point_many/root/test.importmap deleted file mode 100644 index 1001fa5a..00000000 --- a/tests/entry_point_check/entry_point_many/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "root/": "./" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_many_2/entry_point_many_2.test.mjs b/tests/entry_point_check/entry_point_many_2/entry_point_many_2.test.mjs index 27728bc5..d26232bc 100644 --- a/tests/entry_point_check/entry_point_many_2/entry_point_many_2.test.mjs +++ b/tests/entry_point_check/entry_point_many_2/entry_point_many_2.test.mjs @@ -1,43 +1,21 @@ -import { takeDirectorySnapshot } from "@jsenv/snapshot"; -import { copyFileSync } from "@jsenv/filesystem"; - +import { writeFileStructureSync } from "@jsenv/filesystem"; import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const snapshotDirectoryUrl = new URL("./snapshots/", import.meta.url); - -const restoreFixtures = () => { - copyFileSync({ - from: new URL(`./fixtures/index.html`, import.meta.url), - to: new URL("./root/index.html", import.meta.url), - overwrite: true, - }); - copyFileSync({ - from: new URL(`./fixtures/about.html`, import.meta.url), - to: new URL("./root/about.html", import.meta.url), - overwrite: true, - }); -}; - -const directorySnapshot = takeDirectorySnapshot(snapshotDirectoryUrl); -restoreFixtures(); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "index.html": {}, - "about.html": {}, - }, -}); -copyFileSync({ - from: new URL("./root/index.html", import.meta.url), - to: new URL(`./snapshots/index.html`, import.meta.url), - overwrite: true, -}); -copyFileSync({ - from: new URL("./root/about.html", import.meta.url), - to: new URL(`./snapshots/about.html`, import.meta.url), - overwrite: true, -}); -restoreFixtures(); -directorySnapshot.compare(); +writeFileStructureSync( + new URL("./fixtures/", import.meta.url), + new URL("./git_ignored/", import.meta.url), +); +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./git_ignored/", import.meta.url), + importmaps: { + "index.html": {}, + "about.html": {}, + }, + }), + import.meta.url, + `./output/entry_point_many_2.md`, +); diff --git a/tests/entry_point_check/entry_point_many_2/root/about.js b/tests/entry_point_check/entry_point_many_2/fixtures/about.js similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/about.js rename to tests/entry_point_check/entry_point_many_2/fixtures/about.js diff --git a/tests/entry_point_check/entry_point_many_2/root/index.js b/tests/entry_point_check/entry_point_many_2/fixtures/index.js similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/index.js rename to tests/entry_point_check/entry_point_many_2/fixtures/index.js diff --git a/tests/entry_point_check/entry_point_many_2/root/node_modules/foo/a.js b/tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/a.js similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/node_modules/foo/a.js rename to tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/a.js diff --git a/tests/entry_point_check/entry_point_many_2/root/node_modules/foo/b.js b/tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/b.js similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/node_modules/foo/b.js rename to tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/b.js diff --git a/tests/entry_point_check/entry_point_many_2/root/node_modules/foo/foo.js b/tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/foo.js similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/node_modules/foo/foo.js rename to tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/foo.js diff --git a/tests/entry_point_check/entry_point_many_2/root/node_modules/foo/package.json b/tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/package.json similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/node_modules/foo/package.json rename to tests/entry_point_check/entry_point_many_2/fixtures/node_modules/foo/package.json diff --git a/tests/entry_point_check/entry_point_many_2/root/package.json b/tests/entry_point_check/entry_point_many_2/fixtures/package.json similarity index 100% rename from tests/entry_point_check/entry_point_many_2/root/package.json rename to tests/entry_point_check/entry_point_many_2/fixtures/package.json diff --git a/tests/entry_point_check/entry_point_many_2/output/entry_point_many_2.md b/tests/entry_point_check/entry_point_many_2/output/entry_point_many_2.md new file mode 100644 index 00000000..a76cd13f --- /dev/null +++ b/tests/entry_point_check/entry_point_many_2/output/entry_point_many_2.md @@ -0,0 +1,71 @@ +1. return promise + +2. write file "git_ignored/index.html" +```html + + + + Title + + + + + + + + + +``` + +3. write file "git_ignored/about.html" +```html + + + + Title + + + + + + + + + +``` + +4. resolve +```js +{ + "index.html": { + "imports": { + "foo/a": "./node_modules/foo/a.js", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + }, + "about.html": { + "imports": { + "foo/b": "./node_modules/foo/b.js", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_many_2/root/about.html b/tests/entry_point_check/entry_point_many_2/root/about.html deleted file mode 100644 index 4f4a74af..00000000 --- a/tests/entry_point_check/entry_point_many_2/root/about.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - Title - - - - - - - - - diff --git a/tests/entry_point_check/entry_point_many_2/root/index.html b/tests/entry_point_check/entry_point_many_2/root/index.html deleted file mode 100644 index c2a4ccca..00000000 --- a/tests/entry_point_check/entry_point_many_2/root/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Title - - - - - - - - diff --git a/tests/entry_point_check/entry_point_many_2/snapshots/about.html b/tests/entry_point_check/entry_point_many_2/snapshots/about.html deleted file mode 100644 index a5565b9c..00000000 --- a/tests/entry_point_check/entry_point_many_2/snapshots/about.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - Title - - - - - - - - - \ No newline at end of file diff --git a/tests/entry_point_check/entry_point_many_2/snapshots/index.html b/tests/entry_point_check/entry_point_many_2/snapshots/index.html deleted file mode 100644 index 59631dab..00000000 --- a/tests/entry_point_check/entry_point_many_2/snapshots/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - Title - - - - - - - - - \ No newline at end of file diff --git a/tests/entry_point_check/extensionless_and_exports/extensionless_and_exports.test.mjs b/tests/entry_point_check/extensionless_and_exports/extensionless_and_exports.test.mjs index 3e144ae1..273cea32 100644 --- a/tests/entry_point_check/extensionless_and_exports/extensionless_and_exports.test.mjs +++ b/tests/entry_point_check/extensionless_and_exports/extensionless_and_exports.test.mjs @@ -1,20 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "./test.importmap": { - importResolution: { - entryPoints: ["./index.js"], - magicExtensions: ["inherit"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "./test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + magicExtensions: ["inherit"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/extensionless_and_exports.md`, +); diff --git a/tests/entry_point_check/extensionless_and_exports/root/index.js b/tests/entry_point_check/extensionless_and_exports/input/index.js similarity index 100% rename from tests/entry_point_check/extensionless_and_exports/root/index.js rename to tests/entry_point_check/extensionless_and_exports/input/index.js diff --git a/tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/file.js b/tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/file.js similarity index 100% rename from tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/file.js rename to tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/file.js diff --git a/tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/index.js b/tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/index.js similarity index 100% rename from tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/index.js rename to tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/index.js diff --git a/tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/package.json b/tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/package.json similarity index 100% rename from tests/entry_point_check/extensionless_and_exports/root/node_modules/foo/package.json rename to tests/entry_point_check/extensionless_and_exports/input/node_modules/foo/package.json diff --git a/tests/entry_point_check/extensionless_and_exports/root/package.json b/tests/entry_point_check/extensionless_and_exports/input/package.json similarity index 100% rename from tests/entry_point_check/extensionless_and_exports/root/package.json rename to tests/entry_point_check/extensionless_and_exports/input/package.json diff --git a/tests/entry_point_check/extensionless_and_exports/output/extensionless_and_exports.md b/tests/entry_point_check/extensionless_and_exports/output/extensionless_and_exports.md new file mode 100644 index 00000000..4aadc0e3 --- /dev/null +++ b/tests/entry_point_check/extensionless_and_exports/output/extensionless_and_exports.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "foo/file.js": "./node_modules/foo/file.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "./test.importmap": { + "imports": { + "foo/file.js": "./node_modules/foo/file.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/extensionless_and_exports/root/test.importmap b/tests/entry_point_check/extensionless_and_exports/root/test.importmap deleted file mode 100644 index 83144827..00000000 --- a/tests/entry_point_check/extensionless_and_exports/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "foo/file.js": "./node_modules/foo/file.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_circular/root/a.js b/tests/entry_point_check/js_import_circular/input/a.js similarity index 100% rename from tests/entry_point_check/js_import_circular/root/a.js rename to tests/entry_point_check/js_import_circular/input/a.js diff --git a/tests/entry_point_check/js_import_circular/root/index.js b/tests/entry_point_check/js_import_circular/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_circular/root/index.js rename to tests/entry_point_check/js_import_circular/input/index.js diff --git a/tests/entry_point_check/js_import_circular/root/package.json b/tests/entry_point_check/js_import_circular/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_circular/root/package.json rename to tests/entry_point_check/js_import_circular/input/package.json diff --git a/tests/entry_point_check/js_import_circular/js_import_circular.test.mjs b/tests/entry_point_check/js_import_circular/js_import_circular.test.mjs index a97d0d00..4fd5f44c 100644 --- a/tests/entry_point_check/js_import_circular/js_import_circular.test.mjs +++ b/tests/entry_point_check/js_import_circular/js_import_circular.test.mjs @@ -1,19 +1,19 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_circular.md`, +); diff --git a/tests/entry_point_check/js_import_circular/output/js_import_circular.md b/tests/entry_point_check/js_import_circular/output/js_import_circular.md new file mode 100644 index 00000000..22bbaa49 --- /dev/null +++ b/tests/entry_point_check/js_import_circular/output/js_import_circular.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_circular/root/test.importmap b/tests/entry_point_check/js_import_circular/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_circular/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_circular_deep/root/a.js b/tests/entry_point_check/js_import_circular_deep/input/a.js similarity index 100% rename from tests/entry_point_check/js_import_circular_deep/root/a.js rename to tests/entry_point_check/js_import_circular_deep/input/a.js diff --git a/tests/entry_point_check/js_import_circular_deep/root/b.js b/tests/entry_point_check/js_import_circular_deep/input/b.js similarity index 100% rename from tests/entry_point_check/js_import_circular_deep/root/b.js rename to tests/entry_point_check/js_import_circular_deep/input/b.js diff --git a/tests/entry_point_check/js_import_circular_deep/root/index.js b/tests/entry_point_check/js_import_circular_deep/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_circular_deep/root/index.js rename to tests/entry_point_check/js_import_circular_deep/input/index.js diff --git a/tests/entry_point_check/js_import_circular_deep/root/package.json b/tests/entry_point_check/js_import_circular_deep/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_circular_deep/root/package.json rename to tests/entry_point_check/js_import_circular_deep/input/package.json diff --git a/tests/entry_point_check/js_import_circular_deep/js_import_circular_deep.test.mjs b/tests/entry_point_check/js_import_circular_deep/js_import_circular_deep.test.mjs index e17bdfb5..2f081e13 100644 --- a/tests/entry_point_check/js_import_circular_deep/js_import_circular_deep.test.mjs +++ b/tests/entry_point_check/js_import_circular_deep/js_import_circular_deep.test.mjs @@ -1,18 +1,19 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_circular_deep.md`, +); diff --git a/tests/entry_point_check/js_import_circular_deep/output/js_import_circular_deep.md b/tests/entry_point_check/js_import_circular_deep/output/js_import_circular_deep.md new file mode 100644 index 00000000..22bbaa49 --- /dev/null +++ b/tests/entry_point_check/js_import_circular_deep/output/js_import_circular_deep.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_circular_deep/root/test.importmap b/tests/entry_point_check/js_import_circular_deep/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_circular_deep/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_fs/root/index.js b/tests/entry_point_check/js_import_fs/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_fs/root/index.js rename to tests/entry_point_check/js_import_fs/input/index.js diff --git a/tests/entry_point_check/js_import_fs/root/package.json b/tests/entry_point_check/js_import_fs/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_fs/root/package.json rename to tests/entry_point_check/js_import_fs/input/package.json diff --git a/tests/entry_point_check/js_import_fs/js_import_fs.test.mjs b/tests/entry_point_check/js_import_fs/js_import_fs.test.mjs index 2dffceea..5d980626 100644 --- a/tests/entry_point_check/js_import_fs/js_import_fs.test.mjs +++ b/tests/entry_point_check/js_import_fs/js_import_fs.test.mjs @@ -1,56 +1,29 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { assert } from "@jsenv/assert"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const test = async ({ name, runtime, expectedWarnings }) => { - const importmapFileRelativeUrl = `${name}.importmap`; - const importmapFileUrl = new URL(importmapFileRelativeUrl, testDirectoryUrl); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - [importmapFileRelativeUrl]: { - importResolution: { - entryPoints: ["./index.js"], - runtime, +const test = async (scenario, { runtime }) => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + [`${scenario}.importmap`]: { + importResolution: { + entryPoints: ["./index.js"], + runtime, + }, + }, }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - importmapFileSnapshot.compare(); - const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); + }), + import.meta.url, + `./output/${scenario}.md`, + ); }; -await test({ - name: "runtime_browser", - expectedWarnings: [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "fs" ---- import trace --- -${testDirectoryUrl}index.js:1:7 -> 1 | import "fs"; - | ^ - 2 |${" "} ---- reason --- -there is no mapping for this bare specifier ---- suggestion 1 --- -use runtime: "node"`, - }, - ], +await test("0_import_fs_browser", { + runtime: "browser", }); - -await test({ - name: "runtime_node", +await test("1_import_fs_node", { runtime: "node", - expectedWarnings: [], }); diff --git a/tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md b/tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md new file mode 100644 index 00000000..464f17d5 --- /dev/null +++ b/tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md @@ -0,0 +1,35 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "fs" +--- import trace --- +file:////input/index.js:1:7 +> 1 | import "fs"; + | ^ + 2 | +--- reason --- +there is no mapping for this bare specifier +--- suggestion 1 --- +use runtime: "node" + +``` + +3. write file "input/0_import_fs_browser.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +4. resolve +```js +{ + "0_import_fs_browser.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_fs/output/1_import_fs_node.md b/tests/entry_point_check/js_import_fs/output/1_import_fs_node.md new file mode 100644 index 00000000..a4dbc1ec --- /dev/null +++ b/tests/entry_point_check/js_import_fs/output/1_import_fs_node.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/1_import_fs_node.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "1_import_fs_node.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_fs/root/runtime_browser.importmap b/tests/entry_point_check/js_import_fs/root/runtime_browser.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_fs/root/runtime_browser.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_fs/root/runtime_node.importmap b/tests/entry_point_check/js_import_fs/root/runtime_node.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_fs/root/runtime_node.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_http/root/index.js b/tests/entry_point_check/js_import_http/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_http/root/index.js rename to tests/entry_point_check/js_import_http/input/index.js diff --git a/tests/entry_point_check/js_import_http/root/package.json b/tests/entry_point_check/js_import_http/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_http/root/package.json rename to tests/entry_point_check/js_import_http/input/package.json diff --git a/tests/entry_point_check/js_import_http/js_import_http.test.mjs b/tests/entry_point_check/js_import_http/js_import_http.test.mjs index b3b31a25..15158751 100644 --- a/tests/entry_point_check/js_import_http/js_import_http.test.mjs +++ b/tests/entry_point_check/js_import_http/js_import_http.test.mjs @@ -1,24 +1,24 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - manualImportmap: { - imports: { - "http://example.com/foo.js": "http://example.com/bar.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + manualImportmap: { + imports: { + "http://example.com/foo.js": "http://example.com/bar.js", + }, + }, + importResolution: { + entryPoints: ["./index.js"], + }, }, }, - importResolution: { - entryPoints: ["./index.js"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_http.md`, +); diff --git a/tests/entry_point_check/js_import_http/output/js_import_http.md b/tests/entry_point_check/js_import_http/output/js_import_http.md new file mode 100644 index 00000000..7984b0cb --- /dev/null +++ b/tests/entry_point_check/js_import_http/output/js_import_http.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "http://example.com/foo.js": "http://example.com/bar.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "http://example.com/foo.js": "http://example.com/bar.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_http/root/test.importmap b/tests/entry_point_check/js_import_http/root/test.importmap deleted file mode 100644 index 6546e656..00000000 --- a/tests/entry_point_check/js_import_http/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "http://example.com/foo.js": "http://example.com/bar.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_leading_slash/root/foo.js b/tests/entry_point_check/js_import_leading_slash/input/foo.js similarity index 100% rename from tests/entry_point_check/js_import_leading_slash/root/foo.js rename to tests/entry_point_check/js_import_leading_slash/input/foo.js diff --git a/tests/entry_point_check/js_import_leading_slash/root/main.js b/tests/entry_point_check/js_import_leading_slash/input/main.js similarity index 100% rename from tests/entry_point_check/js_import_leading_slash/root/main.js rename to tests/entry_point_check/js_import_leading_slash/input/main.js diff --git a/tests/entry_point_check/js_import_leading_slash/root/package.json b/tests/entry_point_check/js_import_leading_slash/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_leading_slash/root/package.json rename to tests/entry_point_check/js_import_leading_slash/input/package.json diff --git a/tests/entry_point_check/js_import_leading_slash/js_import_leading_slash.test.mjs b/tests/entry_point_check/js_import_leading_slash/js_import_leading_slash.test.mjs index 67d3a625..3ae97c95 100644 --- a/tests/entry_point_check/js_import_leading_slash/js_import_leading_slash.test.mjs +++ b/tests/entry_point_check/js_import_leading_slash/js_import_leading_slash.test.mjs @@ -1,63 +1,34 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { assert } from "@jsenv/assert"; -import { urlToFileSystemPath } from "@jsenv/urls"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; if (process.platform === "win32") { // TODO: make it work on windows process.exit(0); } -const testDirectoryUrl = new URL("./root/", import.meta.url); -const test = async ({ name, runtime }) => { - const importmapFileRelativeUrl = `${name}.importmap`; - const importmapFileUrl = new URL(importmapFileRelativeUrl, testDirectoryUrl); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - [importmapFileRelativeUrl]: { - importResolution: { - runtime, - entryPoints: ["./main.js"], - }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); - }, - }); - importmapFileSnapshot.compare(); - const actual = warnings; - const expected = - runtime === "node" - ? [ - { - code: "IMPORT_RESOLUTION_FAILED", - message: `Import resolution failed for "/foo.js" ---- import trace --- -${testDirectoryUrl}main.js:2:7 - 1 | // eslint-disable-next-line import/no-unresolved -> 2 | import "/foo.js"; - | ^ - 3 |${" "} ---- reason --- -file not found on filesystem at ${urlToFileSystemPath("file:///foo.js")}`, +const test = async (scenario, { runtime }) => { + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + [`${scenario}.importmap`]: { + importResolution: { + entryPoints: ["./main.js"], + runtime, + }, }, - ] - : []; - assert({ actual, expected }); + }, + }), + import.meta.url, + `./output/${scenario}.md`, + ); }; -await test({ - name: "runtime_browser", +await test("0_leading_slash_browser", { runtime: "browser", }); - -await test({ - name: "runtime_node", +await test("1_leading_slash_node", { runtime: "node", }); diff --git a/tests/entry_point_check/js_import_leading_slash/output/0_leading_slash_browser.md b/tests/entry_point_check/js_import_leading_slash/output/0_leading_slash_browser.md new file mode 100644 index 00000000..56660069 --- /dev/null +++ b/tests/entry_point_check/js_import_leading_slash/output/0_leading_slash_browser.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/0_leading_slash_browser.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "0_leading_slash_browser.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_leading_slash/output/1_leading_slash_node.md b/tests/entry_point_check/js_import_leading_slash/output/1_leading_slash_node.md new file mode 100644 index 00000000..7513066e --- /dev/null +++ b/tests/entry_point_check/js_import_leading_slash/output/1_leading_slash_node.md @@ -0,0 +1,34 @@ +1. return promise + +2. console.warn +```console + +Import resolution failed for "/foo.js" +--- import trace --- +file:////input/main.js:2:7 + 1 | // eslint-disable-next-line import/no-unresolved +> 2 | import "/foo.js"; + | ^ + 3 | +--- reason --- +file not found on filesystem at /foo.js + +``` + +3. write file "input/1_leading_slash_node.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +4. resolve +```js +{ + "1_leading_slash_node.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_leading_slash/root/runtime_browser.importmap b/tests/entry_point_check/js_import_leading_slash/root/runtime_browser.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_leading_slash/root/runtime_browser.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_leading_slash/root/runtime_node.importmap b/tests/entry_point_check/js_import_leading_slash/root/runtime_node.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_leading_slash/root/runtime_node.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_node_scheme/root/index.js b/tests/entry_point_check/js_import_node_scheme/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_node_scheme/root/index.js rename to tests/entry_point_check/js_import_node_scheme/input/index.js diff --git a/tests/entry_point_check/js_import_node_scheme/root/package.json b/tests/entry_point_check/js_import_node_scheme/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_node_scheme/root/package.json rename to tests/entry_point_check/js_import_node_scheme/input/package.json diff --git a/tests/entry_point_check/js_import_node_scheme/js_import_node_scheme.test.mjs b/tests/entry_point_check/js_import_node_scheme/js_import_node_scheme.test.mjs index 48ce0b27..74930d3d 100644 --- a/tests/entry_point_check/js_import_node_scheme/js_import_node_scheme.test.mjs +++ b/tests/entry_point_check/js_import_node_scheme/js_import_node_scheme.test.mjs @@ -1,20 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - runtime: "node", - entryPoints: ["./index.js"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + runtime: "node", + entryPoints: ["./index.js"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_node_scheme.md`, +); diff --git a/tests/entry_point_check/js_import_node_scheme/output/js_import_node_scheme.md b/tests/entry_point_check/js_import_node_scheme/output/js_import_node_scheme.md new file mode 100644 index 00000000..22bbaa49 --- /dev/null +++ b/tests/entry_point_check/js_import_node_scheme/output/js_import_node_scheme.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_node_scheme/root/test.importmap b/tests/entry_point_check/js_import_node_scheme/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_import_node_scheme/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/index.js b/tests/entry_point_check/js_import_referencing_dependency_package_name/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_dependency_package_name/root/index.js rename to tests/entry_point_check/js_import_referencing_dependency_package_name/input/index.js diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/node_modules/foo/index.js b/tests/entry_point_check/js_import_referencing_dependency_package_name/input/node_modules/foo/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_dependency_package_name/root/node_modules/foo/index.js rename to tests/entry_point_check/js_import_referencing_dependency_package_name/input/node_modules/foo/index.js diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/node_modules/foo/package.json b/tests/entry_point_check/js_import_referencing_dependency_package_name/input/node_modules/foo/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_dependency_package_name/root/node_modules/foo/package.json rename to tests/entry_point_check/js_import_referencing_dependency_package_name/input/node_modules/foo/package.json diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/package.json b/tests/entry_point_check/js_import_referencing_dependency_package_name/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_dependency_package_name/root/package.json rename to tests/entry_point_check/js_import_referencing_dependency_package_name/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/js_import_referencing_dependency_package_name.test.mjs b/tests/entry_point_check/js_import_referencing_dependency_package_name/js_import_referencing_dependency_package_name.test.mjs index d93d1df9..3673d81e 100644 --- a/tests/entry_point_check/js_import_referencing_dependency_package_name/js_import_referencing_dependency_package_name.test.mjs +++ b/tests/entry_point_check/js_import_referencing_dependency_package_name/js_import_referencing_dependency_package_name.test.mjs @@ -1,20 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], - keepUnusedMappings: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + keepUnusedMappings: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_dependency_package_name.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/output/js_import_referencing_dependency_package_name.md b/tests/entry_point_check/js_import_referencing_dependency_package_name/output/js_import_referencing_dependency_package_name.md new file mode 100644 index 00000000..89a264d9 --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_dependency_package_name/output/js_import_referencing_dependency_package_name.md @@ -0,0 +1,29 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index.js", + "foo": "./node_modules/foo/index.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index.js", + "foo": "./node_modules/foo/index.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/test.importmap b/tests/entry_point_check/js_import_referencing_dependency_package_name/root/test.importmap deleted file mode 100644 index bdc8373a..00000000 --- a/tests/entry_point_check/js_import_referencing_dependency_package_name/root/test.importmap +++ /dev/null @@ -1,9 +0,0 @@ -{ - "imports": { - "root/": "./", - "foo/": "./node_modules/foo/", - "root": "./index.js", - "foo": "./node_modules/foo/index.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/index.js b/tests/entry_point_check/js_import_referencing_many_package_name/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/index.js rename to tests/entry_point_check/js_import_referencing_many_package_name/input/index.js index 3fe9876f..58d5aafe 100644 --- a/tests/entry_point_check/js_import_referencing_many_package_name/root/index.js +++ b/tests/entry_point_check/js_import_referencing_many_package_name/input/index.js @@ -1,6 +1,6 @@ /* eslint-disable import/no-unresolved */ import "foo"; -import "foo/index"; import "foo/bar"; -import "root/index.js"; +import "foo/index"; import "root/boo"; +import "root/index.js"; diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/lib/boo.js b/tests/entry_point_check/js_import_referencing_many_package_name/input/lib/boo.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/lib/boo.js rename to tests/entry_point_check/js_import_referencing_many_package_name/input/lib/boo.js diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/index b/tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/index similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/index rename to tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/index diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/package.json b/tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/package.json rename to tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/package.json diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/src/bar.js b/tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/src/bar.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/node_modules/foo/src/bar.js rename to tests/entry_point_check/js_import_referencing_many_package_name/input/node_modules/foo/src/bar.js diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/package.json b/tests/entry_point_check/js_import_referencing_many_package_name/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_many_package_name/root/package.json rename to tests/entry_point_check/js_import_referencing_many_package_name/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/js_import_referencing_many_package_name.test.mjs b/tests/entry_point_check/js_import_referencing_many_package_name/js_import_referencing_many_package_name.test.mjs index d93d1df9..8006a420 100644 --- a/tests/entry_point_check/js_import_referencing_many_package_name/js_import_referencing_many_package_name.test.mjs +++ b/tests/entry_point_check/js_import_referencing_many_package_name/js_import_referencing_many_package_name.test.mjs @@ -1,20 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], - keepUnusedMappings: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + keepUnusedMappings: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_many_package_name.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/output/js_import_referencing_many_package_name.md b/tests/entry_point_check/js_import_referencing_many_package_name/output/js_import_referencing_many_package_name.md new file mode 100644 index 00000000..98c0bd76 --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_many_package_name/output/js_import_referencing_many_package_name.md @@ -0,0 +1,33 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "root/boo": "./lib/boo.js", + "foo/bar": "./node_modules/foo/src/bar.js", + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index.js", + "foo": "./node_modules/foo/index" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "root/boo": "./lib/boo.js", + "foo/bar": "./node_modules/foo/src/bar.js", + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index.js", + "foo": "./node_modules/foo/index" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_many_package_name/root/test.importmap b/tests/entry_point_check/js_import_referencing_many_package_name/root/test.importmap deleted file mode 100644 index de80c538..00000000 --- a/tests/entry_point_check/js_import_referencing_many_package_name/root/test.importmap +++ /dev/null @@ -1,11 +0,0 @@ -{ - "imports": { - "root/boo": "./lib/boo.js", - "foo/bar": "./node_modules/foo/src/bar.js", - "root/": "./", - "foo/": "./node_modules/foo/", - "root": "./index.js", - "foo": "./node_modules/foo/index" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/root/file.js b/tests/entry_point_check/js_import_referencing_root_package_name/input/file.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_root_package_name/root/file.js rename to tests/entry_point_check/js_import_referencing_root_package_name/input/file.js diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/root/index.js b/tests/entry_point_check/js_import_referencing_root_package_name/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_root_package_name/root/index.js rename to tests/entry_point_check/js_import_referencing_root_package_name/input/index.js diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/root/package.json b/tests/entry_point_check/js_import_referencing_root_package_name/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_root_package_name/root/package.json rename to tests/entry_point_check/js_import_referencing_root_package_name/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/js_import_referencing_root_package_name.test.mjs b/tests/entry_point_check/js_import_referencing_root_package_name/js_import_referencing_root_package_name.test.mjs index d93d1df9..de6889b9 100644 --- a/tests/entry_point_check/js_import_referencing_root_package_name/js_import_referencing_root_package_name.test.mjs +++ b/tests/entry_point_check/js_import_referencing_root_package_name/js_import_referencing_root_package_name.test.mjs @@ -1,20 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], - keepUnusedMappings: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + keepUnusedMappings: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_root_package_name.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/output/js_import_referencing_root_package_name.md b/tests/entry_point_check/js_import_referencing_root_package_name/output/js_import_referencing_root_package_name.md new file mode 100644 index 00000000..1b119a68 --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_root_package_name/output/js_import_referencing_root_package_name.md @@ -0,0 +1,25 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "root/": "./", + "root": "./index.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "root/": "./", + "root": "./index.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_root_package_name/root/test.importmap b/tests/entry_point_check/js_import_referencing_root_package_name/root/test.importmap deleted file mode 100644 index 0df014bc..00000000 --- a/tests/entry_point_check/js_import_referencing_root_package_name/root/test.importmap +++ /dev/null @@ -1,7 +0,0 @@ -{ - "imports": { - "root/": "./", - "root": "./index.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/index.js b/tests/entry_point_check/js_import_referencing_subpath_all_exported/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported/root/index.js rename to tests/entry_point_check/js_import_referencing_subpath_all_exported/input/index.js diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/node_modules/@jsenv/core/package.json b/tests/entry_point_check/js_import_referencing_subpath_all_exported/input/node_modules/@jsenv/core/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported/root/node_modules/@jsenv/core/package.json rename to tests/entry_point_check/js_import_referencing_subpath_all_exported/input/node_modules/@jsenv/core/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/package.json b/tests/entry_point_check/js_import_referencing_subpath_all_exported/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported/root/package.json rename to tests/entry_point_check/js_import_referencing_subpath_all_exported/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/js_import_referencing_subpath_all_exported.test.mjs b/tests/entry_point_check/js_import_referencing_subpath_all_exported/js_import_referencing_subpath_all_exported.test.mjs index d8fa24d0..ec6d8870 100644 --- a/tests/entry_point_check/js_import_referencing_subpath_all_exported/js_import_referencing_subpath_all_exported.test.mjs +++ b/tests/entry_point_check/js_import_referencing_subpath_all_exported/js_import_referencing_subpath_all_exported.test.mjs @@ -1,23 +1,23 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - nodeMappings: { - devDependencies: true, - }, - importResolution: { - entryPoints: ["./index.js"], - keepUnusedMappings: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + nodeMappings: { + devDependencies: true, + }, + importResolution: { + entryPoints: ["./index.js"], + keepUnusedMappings: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_subpath_all_exported.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/output/js_import_referencing_subpath_all_exported.md b/tests/entry_point_check/js_import_referencing_subpath_all_exported/output/js_import_referencing_subpath_all_exported.md new file mode 100644 index 00000000..c112e916 --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_subpath_all_exported/output/js_import_referencing_subpath_all_exported.md @@ -0,0 +1,33 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "@jsenv/core/": "./", + "@jsenv/core": "./index.js" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/": "./node_modules/@jsenv/core/" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "@jsenv/core/": "./", + "@jsenv/core": "./index.js" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/": "./node_modules/@jsenv/core/" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/test.importmap b/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/test.importmap deleted file mode 100644 index 54a5da98..00000000 --- a/tests/entry_point_check/js_import_referencing_subpath_all_exported/root/test.importmap +++ /dev/null @@ -1,11 +0,0 @@ -{ - "imports": { - "@jsenv/core/": "./", - "@jsenv/core": "./index.js" - }, - "scopes": { - "./node_modules/@jsenv/core/": { - "@jsenv/core/": "./node_modules/@jsenv/core/" - } - } -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/index b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/index similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/index rename to tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/index diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/node_modules/@jsenv/core/index b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/node_modules/@jsenv/core/index similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/node_modules/@jsenv/core/index rename to tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/node_modules/@jsenv/core/index diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/node_modules/@jsenv/core/package.json b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/node_modules/@jsenv/core/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/node_modules/@jsenv/core/package.json rename to tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/node_modules/@jsenv/core/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/package.json b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/package.json rename to tests/entry_point_check/js_import_referencing_subpath_all_exported_2/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/js_import_referencing_subpath_all_exported_2.test.mjs b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/js_import_referencing_subpath_all_exported_2.test.mjs index 82d451c3..ed3b95af 100644 --- a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/js_import_referencing_subpath_all_exported_2.test.mjs +++ b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/js_import_referencing_subpath_all_exported_2.test.mjs @@ -1,23 +1,23 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - nodeMappings: { - devDependencies: true, - }, - importResolution: { - entryPoints: ["./index"], - keepUnusedMappings: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + nodeMappings: { + devDependencies: true, + }, + importResolution: { + entryPoints: ["./index"], + keepUnusedMappings: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_subpath_all_exported_2.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/output/js_import_referencing_subpath_all_exported_2.md b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/output/js_import_referencing_subpath_all_exported_2.md new file mode 100644 index 00000000..73139687 --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/output/js_import_referencing_subpath_all_exported_2.md @@ -0,0 +1,35 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "@jsenv/core/": "./", + "@jsenv/core": "./index" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/": "./node_modules/@jsenv/core/", + "@jsenv/core": "./node_modules/@jsenv/core/index" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "@jsenv/core/": "./", + "@jsenv/core": "./index" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/": "./node_modules/@jsenv/core/", + "@jsenv/core": "./node_modules/@jsenv/core/index" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/test.importmap b/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/test.importmap deleted file mode 100644 index 6e30696a..00000000 --- a/tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/test.importmap +++ /dev/null @@ -1,12 +0,0 @@ -{ - "imports": { - "@jsenv/core/": "./", - "@jsenv/core": "./index" - }, - "scopes": { - "./node_modules/@jsenv/core/": { - "@jsenv/core/": "./node_modules/@jsenv/core/", - "@jsenv/core": "./node_modules/@jsenv/core/index" - } - } -} \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/root/index.js b/tests/entry_point_check/js_import_referencing_subpath_exported/input/index.js similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_exported/root/index.js rename to tests/entry_point_check/js_import_referencing_subpath_exported/input/index.js diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/root/node_modules/@jsenv/core/package.json b/tests/entry_point_check/js_import_referencing_subpath_exported/input/node_modules/@jsenv/core/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_exported/root/node_modules/@jsenv/core/package.json rename to tests/entry_point_check/js_import_referencing_subpath_exported/input/node_modules/@jsenv/core/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/root/package.json b/tests/entry_point_check/js_import_referencing_subpath_exported/input/package.json similarity index 100% rename from tests/entry_point_check/js_import_referencing_subpath_exported/root/package.json rename to tests/entry_point_check/js_import_referencing_subpath_exported/input/package.json diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/js_import_referencing_subpath_exported.test.mjs b/tests/entry_point_check/js_import_referencing_subpath_exported/js_import_referencing_subpath_exported.test.mjs index 54f7ae6b..32aa207f 100644 --- a/tests/entry_point_check/js_import_referencing_subpath_exported/js_import_referencing_subpath_exported.test.mjs +++ b/tests/entry_point_check/js_import_referencing_subpath_exported/js_import_referencing_subpath_exported.test.mjs @@ -1,19 +1,19 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - nodeMappings: { - devDependencies: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + nodeMappings: { + devDependencies: true, + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_import_referencing_subpath_exported.md`, +); diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/output/js_import_referencing_subpath_exported.md b/tests/entry_point_check/js_import_referencing_subpath_exported/output/js_import_referencing_subpath_exported.md new file mode 100644 index 00000000..27ae24af --- /dev/null +++ b/tests/entry_point_check/js_import_referencing_subpath_exported/output/js_import_referencing_subpath_exported.md @@ -0,0 +1,39 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "@jsenv/core/conflict": "./root.js", + "@jsenv/core/rootonly": "./rootonly.js", + "@jsenv/core/deponly": "./node_modules/@jsenv/core/deponly.js", + "@jsenv/core": "./index.js" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/conflict": "./node_modules/@jsenv/core/dep.js", + "@jsenv/core": "./node_modules/@jsenv/core/maindep.js" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "@jsenv/core/conflict": "./root.js", + "@jsenv/core/rootonly": "./rootonly.js", + "@jsenv/core/deponly": "./node_modules/@jsenv/core/deponly.js", + "@jsenv/core": "./index.js" + }, + "scopes": { + "./node_modules/@jsenv/core/": { + "@jsenv/core/conflict": "./node_modules/@jsenv/core/dep.js", + "@jsenv/core": "./node_modules/@jsenv/core/maindep.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_referencing_subpath_exported/root/test.importmap b/tests/entry_point_check/js_import_referencing_subpath_exported/root/test.importmap deleted file mode 100644 index c4b53369..00000000 --- a/tests/entry_point_check/js_import_referencing_subpath_exported/root/test.importmap +++ /dev/null @@ -1,14 +0,0 @@ -{ - "imports": { - "@jsenv/core/conflict": "./root.js", - "@jsenv/core/rootonly": "./rootonly.js", - "@jsenv/core/deponly": "./node_modules/@jsenv/core/deponly.js", - "@jsenv/core": "./index.js" - }, - "scopes": { - "./node_modules/@jsenv/core/": { - "@jsenv/core/conflict": "./node_modules/@jsenv/core/dep.js", - "@jsenv/core": "./node_modules/@jsenv/core/maindep.js" - } - } -} \ No newline at end of file diff --git a/tests/entry_point_check/js_using_decorators/root/.eslintrc.cjs b/tests/entry_point_check/js_using_decorators/input/.eslintrc.cjs similarity index 100% rename from tests/entry_point_check/js_using_decorators/root/.eslintrc.cjs rename to tests/entry_point_check/js_using_decorators/input/.eslintrc.cjs diff --git a/tests/entry_point_check/js_using_decorators/root/babel.config.cjs b/tests/entry_point_check/js_using_decorators/input/babel.config.cjs similarity index 100% rename from tests/entry_point_check/js_using_decorators/root/babel.config.cjs rename to tests/entry_point_check/js_using_decorators/input/babel.config.cjs diff --git a/tests/entry_point_check/js_using_decorators/root/index.js b/tests/entry_point_check/js_using_decorators/input/index.js similarity index 100% rename from tests/entry_point_check/js_using_decorators/root/index.js rename to tests/entry_point_check/js_using_decorators/input/index.js diff --git a/tests/entry_point_check/js_using_decorators/root/package.json b/tests/entry_point_check/js_using_decorators/input/package.json similarity index 100% rename from tests/entry_point_check/js_using_decorators/root/package.json rename to tests/entry_point_check/js_using_decorators/input/package.json diff --git a/tests/entry_point_check/js_using_decorators/js_using_decorators.test.mjs b/tests/entry_point_check/js_using_decorators/js_using_decorators.test.mjs index a97d0d00..63a06ce5 100644 --- a/tests/entry_point_check/js_using_decorators/js_using_decorators.test.mjs +++ b/tests/entry_point_check/js_using_decorators/js_using_decorators.test.mjs @@ -1,19 +1,19 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - importResolution: { - entryPoints: ["./index.js"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_using_decorators.md`, +); diff --git a/tests/entry_point_check/js_using_decorators/output/js_using_decorators.md b/tests/entry_point_check/js_using_decorators/output/js_using_decorators.md new file mode 100644 index 00000000..22bbaa49 --- /dev/null +++ b/tests/entry_point_check/js_using_decorators/output/js_using_decorators.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_using_decorators/root/test.importmap b/tests/entry_point_check/js_using_decorators/root/test.importmap deleted file mode 100644 index 85f87be0..00000000 --- a/tests/entry_point_check/js_using_decorators/root/test.importmap +++ /dev/null @@ -1,4 +0,0 @@ -{ - "imports": {}, - "scopes": {} -} \ No newline at end of file diff --git a/tests/entry_point_check/js_using_import_assertions/root/file.js b/tests/entry_point_check/js_using_import_assertions/input/file.js similarity index 100% rename from tests/entry_point_check/js_using_import_assertions/root/file.js rename to tests/entry_point_check/js_using_import_assertions/input/file.js diff --git a/tests/entry_point_check/js_using_import_assertions/root/index.js b/tests/entry_point_check/js_using_import_assertions/input/index.js similarity index 100% rename from tests/entry_point_check/js_using_import_assertions/root/index.js rename to tests/entry_point_check/js_using_import_assertions/input/index.js diff --git a/tests/entry_point_check/js_using_import_assertions/js_using_import_assertions.test.mjs b/tests/entry_point_check/js_using_import_assertions/js_using_import_assertions.test.mjs index bd29e49c..2d1b5cca 100644 --- a/tests/entry_point_check/js_using_import_assertions/js_using_import_assertions.test.mjs +++ b/tests/entry_point_check/js_using_import_assertions/js_using_import_assertions.test.mjs @@ -1,21 +1,21 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - nodeMappings: false, - importResolution: { - entryPoints: ["./index.js"], - magicExtensions: ["inherit"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + nodeMappings: false, + importResolution: { + entryPoints: ["./index.js"], + magicExtensions: ["inherit"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/js_using_import_assertions.md`, +); diff --git a/tests/entry_point_check/js_using_import_assertions/output/js_using_import_assertions.md b/tests/entry_point_check/js_using_import_assertions/output/js_using_import_assertions.md new file mode 100644 index 00000000..b1de2b87 --- /dev/null +++ b/tests/entry_point_check/js_using_import_assertions/output/js_using_import_assertions.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "./file": "./file.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "./file": "./file.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_using_import_assertions/root/test.importmap b/tests/entry_point_check/js_using_import_assertions/root/test.importmap deleted file mode 100644 index 92558658..00000000 --- a/tests/entry_point_check/js_using_import_assertions/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "./file": "./file.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/manual_importmap/env_dev/env_dev.test.mjs b/tests/manual_importmap/env_dev/env_dev.test.mjs index 3c6f4337..09282d90 100644 --- a/tests/manual_importmap/env_dev/env_dev.test.mjs +++ b/tests/manual_importmap/env_dev/env_dev.test.mjs @@ -1,24 +1,24 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL(`./root/test.importmap`, import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - manualImportmap: { - imports: { - "#env": "./env.dev.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + manualImportmap: { + imports: { + "#env": "./env.dev.js", + }, + }, + importResolution: { + entryPoints: ["./index.js"], + }, }, }, - importResolution: { - entryPoints: ["./index.js"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/env_dev.md`, +); diff --git a/tests/manual_importmap/env_dev/root/env.dev.js b/tests/manual_importmap/env_dev/input/env.dev.js similarity index 100% rename from tests/manual_importmap/env_dev/root/env.dev.js rename to tests/manual_importmap/env_dev/input/env.dev.js diff --git a/tests/manual_importmap/env_dev/root/index.js b/tests/manual_importmap/env_dev/input/index.js similarity index 100% rename from tests/manual_importmap/env_dev/root/index.js rename to tests/manual_importmap/env_dev/input/index.js diff --git a/tests/manual_importmap/env_dev/root/package.json b/tests/manual_importmap/env_dev/input/package.json similarity index 100% rename from tests/manual_importmap/env_dev/root/package.json rename to tests/manual_importmap/env_dev/input/package.json diff --git a/tests/manual_importmap/env_dev/output/env_dev.md b/tests/manual_importmap/env_dev/output/env_dev.md new file mode 100644 index 00000000..ddca4132 --- /dev/null +++ b/tests/manual_importmap/env_dev/output/env_dev.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "#env": "./env.dev.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "#env": "./env.dev.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/manual_importmap/env_dev/root/test.importmap b/tests/manual_importmap/env_dev/root/test.importmap deleted file mode 100644 index 71243f5f..00000000 --- a/tests/manual_importmap/env_dev/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "#env": "./env.dev.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/manual_importmap/file_override/file_override.test.mjs b/tests/manual_importmap/file_override/file_override.test.mjs index 9240aecb..7009f8e9 100644 --- a/tests/manual_importmap/file_override/file_override.test.mjs +++ b/tests/manual_importmap/file_override/file_override.test.mjs @@ -1,22 +1,23 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL(`./root/test.importmap`, import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - // manualImportmap allows to override the mapping found in package.json - manualImportmap: { - imports: { - "./node_modules/foo/button.css": "./node_modules/foo/button.css.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + // manualImportmap allows to override the mapping found in package.json + manualImportmap: { + imports: { + "./node_modules/foo/button.css": + "./node_modules/foo/button.css.js", + }, + }, }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/file_override.md`, +); diff --git a/tests/manual_importmap/file_override/root/index.mjs b/tests/manual_importmap/file_override/input/index.mjs similarity index 100% rename from tests/manual_importmap/file_override/root/index.mjs rename to tests/manual_importmap/file_override/input/index.mjs diff --git a/tests/manual_importmap/file_override/root/node_modules/foo/button.css.js b/tests/manual_importmap/file_override/input/node_modules/foo/button.css.js similarity index 100% rename from tests/manual_importmap/file_override/root/node_modules/foo/button.css.js rename to tests/manual_importmap/file_override/input/node_modules/foo/button.css.js diff --git a/tests/manual_importmap/file_override/root/node_modules/foo/button.js b/tests/manual_importmap/file_override/input/node_modules/foo/button.js similarity index 100% rename from tests/manual_importmap/file_override/root/node_modules/foo/button.js rename to tests/manual_importmap/file_override/input/node_modules/foo/button.js diff --git a/tests/manual_importmap/file_override/root/node_modules/foo/package.json b/tests/manual_importmap/file_override/input/node_modules/foo/package.json similarity index 100% rename from tests/manual_importmap/file_override/root/node_modules/foo/package.json rename to tests/manual_importmap/file_override/input/node_modules/foo/package.json diff --git a/tests/manual_importmap/file_override/root/package.json b/tests/manual_importmap/file_override/input/package.json similarity index 100% rename from tests/manual_importmap/file_override/root/package.json rename to tests/manual_importmap/file_override/input/package.json diff --git a/tests/manual_importmap/file_override/output/file_override.md b/tests/manual_importmap/file_override/output/file_override.md new file mode 100644 index 00000000..501a6457 --- /dev/null +++ b/tests/manual_importmap/file_override/output/file_override.md @@ -0,0 +1,31 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "./node_modules/foo/button.css": "./node_modules/foo/button.css.js", + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index", + "foo": "./node_modules/foo/index" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "./node_modules/foo/button.css": "./node_modules/foo/button.css.js", + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index", + "foo": "./node_modules/foo/index" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/manual_importmap/file_override/root/test.importmap b/tests/manual_importmap/file_override/root/test.importmap deleted file mode 100644 index 009785c2..00000000 --- a/tests/manual_importmap/file_override/root/test.importmap +++ /dev/null @@ -1,10 +0,0 @@ -{ - "imports": { - "./node_modules/foo/button.css": "./node_modules/foo/button.css.js", - "root/": "./", - "foo/": "./node_modules/foo/", - "root": "./index", - "foo": "./node_modules/foo/index" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/manual_importmap/file_override_scope/file_override_scope.test.mjs b/tests/manual_importmap/file_override_scope/file_override_scope.test.mjs index 4f8760a2..350f102e 100644 --- a/tests/manual_importmap/file_override_scope/file_override_scope.test.mjs +++ b/tests/manual_importmap/file_override_scope/file_override_scope.test.mjs @@ -1,25 +1,26 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL(`./root/test.importmap`, import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - manualImportmap: { - scopes: { - "./node_modules/foo/": { - "bar/button.css": "./node_modules/bar/button.css.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + manualImportmap: { + scopes: { + "./node_modules/foo/": { + "bar/button.css": "./node_modules/bar/button.css.js", + }, + }, + }, + importResolution: { + entryPoints: ["./index.mjs"], }, }, }, - importResolution: { - entryPoints: ["./index.mjs"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/file_override_scope.md`, +); diff --git a/tests/manual_importmap/file_override_scope/root/index.mjs b/tests/manual_importmap/file_override_scope/input/index.mjs similarity index 100% rename from tests/manual_importmap/file_override_scope/root/index.mjs rename to tests/manual_importmap/file_override_scope/input/index.mjs diff --git a/tests/manual_importmap/file_override_scope/root/node_modules/bar/button.css.js b/tests/manual_importmap/file_override_scope/input/node_modules/bar/button.css.js similarity index 100% rename from tests/manual_importmap/file_override_scope/root/node_modules/bar/button.css.js rename to tests/manual_importmap/file_override_scope/input/node_modules/bar/button.css.js diff --git a/tests/manual_importmap/file_override_scope/root/node_modules/bar/package.json b/tests/manual_importmap/file_override_scope/input/node_modules/bar/package.json similarity index 100% rename from tests/manual_importmap/file_override_scope/root/node_modules/bar/package.json rename to tests/manual_importmap/file_override_scope/input/node_modules/bar/package.json diff --git a/tests/manual_importmap/file_override_scope/root/node_modules/foo/index.mjs b/tests/manual_importmap/file_override_scope/input/node_modules/foo/index.mjs similarity index 100% rename from tests/manual_importmap/file_override_scope/root/node_modules/foo/index.mjs rename to tests/manual_importmap/file_override_scope/input/node_modules/foo/index.mjs diff --git a/tests/manual_importmap/file_override_scope/root/node_modules/foo/package.json b/tests/manual_importmap/file_override_scope/input/node_modules/foo/package.json similarity index 100% rename from tests/manual_importmap/file_override_scope/root/node_modules/foo/package.json rename to tests/manual_importmap/file_override_scope/input/node_modules/foo/package.json diff --git a/tests/manual_importmap/file_override_scope/root/package.json b/tests/manual_importmap/file_override_scope/input/package.json similarity index 100% rename from tests/manual_importmap/file_override_scope/root/package.json rename to tests/manual_importmap/file_override_scope/input/package.json diff --git a/tests/manual_importmap/file_override_scope/output/file_override_scope.md b/tests/manual_importmap/file_override_scope/output/file_override_scope.md new file mode 100644 index 00000000..61abc9ec --- /dev/null +++ b/tests/manual_importmap/file_override_scope/output/file_override_scope.md @@ -0,0 +1,31 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "foo": "./node_modules/foo/index.mjs" + }, + "scopes": { + "./node_modules/foo/": { + "bar/button.css": "./node_modules/bar/button.css.js" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "foo": "./node_modules/foo/index.mjs" + }, + "scopes": { + "./node_modules/foo/": { + "bar/button.css": "./node_modules/bar/button.css.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/manual_importmap/file_override_scope/root/test.importmap b/tests/manual_importmap/file_override_scope/root/test.importmap deleted file mode 100644 index 39ff3d23..00000000 --- a/tests/manual_importmap/file_override_scope/root/test.importmap +++ /dev/null @@ -1,10 +0,0 @@ -{ - "imports": { - "foo": "./node_modules/foo/index.mjs" - }, - "scopes": { - "./node_modules/foo/": { - "bar/button.css": "./node_modules/bar/button.css.js" - } - } -} \ No newline at end of file diff --git a/tests/manual_importmap/preact_override/root/index.js b/tests/manual_importmap/preact_override/input/index.js similarity index 100% rename from tests/manual_importmap/preact_override/root/index.js rename to tests/manual_importmap/preact_override/input/index.js diff --git a/tests/manual_importmap/preact_override/root/node_modules/preact/compat/index.js b/tests/manual_importmap/preact_override/input/node_modules/preact/compat/index.js similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/preact/compat/index.js rename to tests/manual_importmap/preact_override/input/node_modules/preact/compat/index.js diff --git a/tests/manual_importmap/preact_override/root/node_modules/preact/index.js b/tests/manual_importmap/preact_override/input/node_modules/preact/index.js similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/preact/index.js rename to tests/manual_importmap/preact_override/input/node_modules/preact/index.js diff --git a/tests/manual_importmap/preact_override/root/node_modules/preact/package.json b/tests/manual_importmap/preact_override/input/node_modules/preact/package.json similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/preact/package.json rename to tests/manual_importmap/preact_override/input/node_modules/preact/package.json diff --git a/tests/manual_importmap/preact_override/root/node_modules/react-redux/index.js b/tests/manual_importmap/preact_override/input/node_modules/react-redux/index.js similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/react-redux/index.js rename to tests/manual_importmap/preact_override/input/node_modules/react-redux/index.js diff --git a/tests/manual_importmap/preact_override/root/node_modules/react-redux/package.json b/tests/manual_importmap/preact_override/input/node_modules/react-redux/package.json similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/react-redux/package.json rename to tests/manual_importmap/preact_override/input/node_modules/react-redux/package.json diff --git a/tests/manual_importmap/preact_override/root/node_modules/react/index.js b/tests/manual_importmap/preact_override/input/node_modules/react/index.js similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/react/index.js rename to tests/manual_importmap/preact_override/input/node_modules/react/index.js diff --git a/tests/manual_importmap/preact_override/root/node_modules/react/package.json b/tests/manual_importmap/preact_override/input/node_modules/react/package.json similarity index 100% rename from tests/manual_importmap/preact_override/root/node_modules/react/package.json rename to tests/manual_importmap/preact_override/input/node_modules/react/package.json diff --git a/tests/manual_importmap/preact_override/root/package.json b/tests/manual_importmap/preact_override/input/package.json similarity index 100% rename from tests/manual_importmap/preact_override/root/package.json rename to tests/manual_importmap/preact_override/input/package.json diff --git a/tests/manual_importmap/preact_override/output/preact_override.md b/tests/manual_importmap/preact_override/output/preact_override.md new file mode 100644 index 00000000..25fd682f --- /dev/null +++ b/tests/manual_importmap/preact_override/output/preact_override.md @@ -0,0 +1,41 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "react-redux/": "./node_modules/react-redux/", + "react-redux": "./node_modules/react-redux/index.js", + "react/": "./node_modules/react/", + "react": "./node_modules/react/index.js", + "root/": "./", + "root": "./index.js" + }, + "scopes": { + "./node_modules/react-redux/": { + "react": "./node_modules/preact/compat/src/index.js" + } + } +} +``` + +3. resolve +```js +{ + "test.importmap": { + "imports": { + "react-redux/": "./node_modules/react-redux/", + "react-redux": "./node_modules/react-redux/index.js", + "react/": "./node_modules/react/", + "react": "./node_modules/react/index.js", + "root/": "./", + "root": "./index.js" + }, + "scopes": { + "./node_modules/react-redux/": { + "react": "./node_modules/preact/compat/src/index.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/manual_importmap/preact_override/preact_override.test.mjs b/tests/manual_importmap/preact_override/preact_override.test.mjs index ae67e4ef..8f845670 100644 --- a/tests/manual_importmap/preact_override/preact_override.test.mjs +++ b/tests/manual_importmap/preact_override/preact_override.test.mjs @@ -1,23 +1,24 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL(`./root/test.importmap`, import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - directoryUrl: testDirectoryUrl, - importmaps: { - "test.importmap": { - // manualImportmap allows to override the mapping found in package.json - manualImportmap: { - scopes: { - "./node_modules/react-redux/": { - react: "./node_modules/preact/compat/src/index.js", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + // manualImportmap allows to override the mapping found in package.json + manualImportmap: { + scopes: { + "./node_modules/react-redux/": { + react: "./node_modules/preact/compat/src/index.js", + }, + }, }, }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/preact_override.md`, +); diff --git a/tests/manual_importmap/preact_override/root/test.importmap b/tests/manual_importmap/preact_override/root/test.importmap deleted file mode 100644 index 820c5630..00000000 --- a/tests/manual_importmap/preact_override/root/test.importmap +++ /dev/null @@ -1,15 +0,0 @@ -{ - "imports": { - "react-redux/": "./node_modules/react-redux/", - "react-redux": "./node_modules/react-redux/index.js", - "react/": "./node_modules/react/", - "react": "./node_modules/react/index.js", - "root/": "./", - "root": "./index.js" - }, - "scopes": { - "./node_modules/react-redux/": { - "react": "./node_modules/preact/compat/src/index.js" - } - } -} \ No newline at end of file diff --git a/tests/node_esm/deep_importmap/deep_importmap.test.mjs b/tests/node_esm/deep_importmap/deep_importmap.test.mjs index a8885797..7d418bfb 100644 --- a/tests/node_esm/deep_importmap/deep_importmap.test.mjs +++ b/tests/node_esm/deep_importmap/deep_importmap.test.mjs @@ -1,28 +1,25 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL( - "./root/src/directory/test.importmap", - import.meta.url, -); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "./src/directory/test.importmap": { - manualImportmap: { - imports: { - "directory/": "./src/directory/", +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "./src/directory/test.importmap": { + manualImportmap: { + imports: { + "directory/": "./src/directory/", + }, + }, + importResolution: { + entryPoints: ["./src/directory/main.js"], + magicExtensions: [".js"], + }, }, }, - importResolution: { - entryPoints: ["./src/directory/main.js"], - magicExtensions: [".js"], - }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/deep_importmap.md`, +); diff --git a/tests/node_esm/deep_importmap/root/node_modules/example/file.js b/tests/node_esm/deep_importmap/input/node_modules/example/file.js similarity index 100% rename from tests/node_esm/deep_importmap/root/node_modules/example/file.js rename to tests/node_esm/deep_importmap/input/node_modules/example/file.js diff --git a/tests/node_esm/deep_importmap/root/node_modules/example/index.js b/tests/node_esm/deep_importmap/input/node_modules/example/index.js similarity index 100% rename from tests/node_esm/deep_importmap/root/node_modules/example/index.js rename to tests/node_esm/deep_importmap/input/node_modules/example/index.js diff --git a/tests/node_esm/deep_importmap/root/node_modules/example/package.json b/tests/node_esm/deep_importmap/input/node_modules/example/package.json similarity index 100% rename from tests/node_esm/deep_importmap/root/node_modules/example/package.json rename to tests/node_esm/deep_importmap/input/node_modules/example/package.json diff --git a/tests/node_esm/deep_importmap/root/package.json b/tests/node_esm/deep_importmap/input/package.json similarity index 100% rename from tests/node_esm/deep_importmap/root/package.json rename to tests/node_esm/deep_importmap/input/package.json diff --git a/tests/node_esm/deep_importmap/root/src/directory/file.js b/tests/node_esm/deep_importmap/input/src/directory/file.js similarity index 100% rename from tests/node_esm/deep_importmap/root/src/directory/file.js rename to tests/node_esm/deep_importmap/input/src/directory/file.js diff --git a/tests/node_esm/deep_importmap/root/src/directory/main.js b/tests/node_esm/deep_importmap/input/src/directory/main.js similarity index 100% rename from tests/node_esm/deep_importmap/root/src/directory/main.js rename to tests/node_esm/deep_importmap/input/src/directory/main.js diff --git a/tests/node_esm/deep_importmap/output/deep_importmap.md b/tests/node_esm/deep_importmap/output/deep_importmap.md new file mode 100644 index 00000000..ce5dc60b --- /dev/null +++ b/tests/node_esm/deep_importmap/output/deep_importmap.md @@ -0,0 +1,33 @@ +1. return promise + +2. write file "input/src/directory/test.importmap" +```importmap +{ + "imports": { + "directory/": "./", + "example": "../../node_modules/example/index.js" + }, + "scopes": { + "../../node_modules/example/": { + "../../node_modules/example/file": "../../node_modules/example/file.js" + } + } +} +``` + +3. resolve +```js +{ + "./src/directory/test.importmap": { + "imports": { + "directory/": "./", + "example": "../../node_modules/example/index.js" + }, + "scopes": { + "../../node_modules/example/": { + "../../node_modules/example/file": "../../node_modules/example/file.js" + } + } + } +} +``` \ No newline at end of file diff --git a/tests/node_esm/deep_importmap/root/src/directory/test.importmap b/tests/node_esm/deep_importmap/root/src/directory/test.importmap deleted file mode 100644 index 8ce27972..00000000 --- a/tests/node_esm/deep_importmap/root/src/directory/test.importmap +++ /dev/null @@ -1,11 +0,0 @@ -{ - "imports": { - "directory/": "./", - "example": "../../node_modules/example/index.js" - }, - "scopes": { - "../../node_modules/example/": { - "../../node_modules/example/file": "../../node_modules/example/file.js" - } - } -} \ No newline at end of file diff --git a/tests/node_esm/dependency_indirect/dependency_indirect.test.mjs b/tests/node_esm/dependency_indirect/dependency_indirect.test.mjs index 5fca9373..0141e1a1 100644 --- a/tests/node_esm/dependency_indirect/dependency_indirect.test.mjs +++ b/tests/node_esm/dependency_indirect/dependency_indirect.test.mjs @@ -3,23 +3,23 @@ * that is not in its own package.json but in one of its dependency package.json */ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const importmapFileUrl = new URL("./root/test.importmap", import.meta.url); -const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "./test.importmap": { - importResolution: { - entryPoints: ["./index.js"], - // magicExtensions: [".js"], +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "./test.importmap": { + importResolution: { + entryPoints: ["./index.js"], + // magicExtensions: [".js"], + }, + }, }, - }, - }, -}); -importmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/dependency_indirect.md`, +); diff --git a/tests/node_esm/dependency_indirect/root/index.js b/tests/node_esm/dependency_indirect/input/index.js similarity index 100% rename from tests/node_esm/dependency_indirect/root/index.js rename to tests/node_esm/dependency_indirect/input/index.js diff --git a/tests/node_esm/dependency_indirect/root/node_modules/a/index.js b/tests/node_esm/dependency_indirect/input/node_modules/a/index.js similarity index 100% rename from tests/node_esm/dependency_indirect/root/node_modules/a/index.js rename to tests/node_esm/dependency_indirect/input/node_modules/a/index.js diff --git a/tests/node_esm/dependency_indirect/root/node_modules/a/package.json b/tests/node_esm/dependency_indirect/input/node_modules/a/package.json similarity index 100% rename from tests/node_esm/dependency_indirect/root/node_modules/a/package.json rename to tests/node_esm/dependency_indirect/input/node_modules/a/package.json diff --git a/tests/node_esm/dependency_indirect/root/node_modules/b/index.js b/tests/node_esm/dependency_indirect/input/node_modules/b/index.js similarity index 100% rename from tests/node_esm/dependency_indirect/root/node_modules/b/index.js rename to tests/node_esm/dependency_indirect/input/node_modules/b/index.js diff --git a/tests/node_esm/dependency_indirect/root/node_modules/b/package.json b/tests/node_esm/dependency_indirect/input/node_modules/b/package.json similarity index 100% rename from tests/node_esm/dependency_indirect/root/node_modules/b/package.json rename to tests/node_esm/dependency_indirect/input/node_modules/b/package.json diff --git a/tests/node_esm/dependency_indirect/root/package.json b/tests/node_esm/dependency_indirect/input/package.json similarity index 100% rename from tests/node_esm/dependency_indirect/root/package.json rename to tests/node_esm/dependency_indirect/input/package.json diff --git a/tests/node_esm/dependency_indirect/output/dependency_indirect.md b/tests/node_esm/dependency_indirect/output/dependency_indirect.md new file mode 100644 index 00000000..9a42c4ba --- /dev/null +++ b/tests/node_esm/dependency_indirect/output/dependency_indirect.md @@ -0,0 +1,23 @@ +1. return promise + +2. write file "input/test.importmap" +```importmap +{ + "imports": { + "b": "./node_modules/b/index.js" + }, + "scopes": {} +} +``` + +3. resolve +```js +{ + "./test.importmap": { + "imports": { + "b": "./node_modules/b/index.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/node_esm/dependency_indirect/root/test.importmap b/tests/node_esm/dependency_indirect/root/test.importmap deleted file mode 100644 index 3b3f9b42..00000000 --- a/tests/node_esm/dependency_indirect/root/test.importmap +++ /dev/null @@ -1,6 +0,0 @@ -{ - "imports": { - "b": "./node_modules/b/index.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/node_esm/dependency_package_inside/dependency_package_inside.test.mjs b/tests/node_esm/dependency_package_inside/dependency_package_inside.test.mjs index 93be52b0..dd1d655e 100644 --- a/tests/node_esm/dependency_package_inside/dependency_package_inside.test.mjs +++ b/tests/node_esm/dependency_package_inside/dependency_package_inside.test.mjs @@ -1,7 +1,7 @@ -import { readFileSync } from "node:fs"; -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; +import { takeFileSnapshot } from "@jsenv/snapshot"; +import { readFileSync } from "node:fs"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -40,9 +40,9 @@ const actual = { importMap: importMapNormalized, }), }; -const expected = { +const expect = { bar_inside_project: `http://example.com/node_modules/bar/bar.js`, bar_inside_foo: `http://example.com/node_modules/foo/node_modules/bar/bar.js`, bar_file_inside_bar: `http://example.com/node_modules/foo/node_modules/bar/file.js`, }; -assert({ actual, expected }); +assert({ actual, expect }); diff --git a/tests/node_esm/dependency_package_many/root/index.js b/tests/node_esm/dependency_package_many/root/index.js index 4e4f98b7..8bfe3ef1 100644 --- a/tests/node_esm/dependency_package_many/root/index.js +++ b/tests/node_esm/dependency_package_many/root/index.js @@ -1,5 +1,5 @@ /* eslint-disable import/no-unresolved */ +import "@dmail/yo"; import "bar"; import "foo"; -import "@dmail/yo"; import "root/index.js"; diff --git a/tests/node_esm/dependency_package_missing/dependency_package_missing.test.mjs b/tests/node_esm/dependency_package_missing/dependency_package_missing.test.mjs index 812501d6..2b7f4438 100644 --- a/tests/node_esm/dependency_package_missing/dependency_package_missing.test.mjs +++ b/tests/node_esm/dependency_package_missing/dependency_package_missing.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -22,7 +22,7 @@ await writeImportmaps({ importmapFileSnapshot.compare(); const actual = warnings; -const expected = [ +const expect = [ { code: "CANNOT_FIND_PACKAGE", message: `cannot find a dependency. @@ -32,4 +32,4 @@ not-found@* ${urlToFileSystemPath(rootPackageFileUrl)}`, }, ]; -assert({ actual, expected }); +assert({ actual, expect }); diff --git a/tests/node_esm/dependency_package_outside_project/dependency_package_outside_project.test.mjs b/tests/node_esm/dependency_package_outside_project/dependency_package_outside_project.test.mjs index abd65b23..49c32557 100644 --- a/tests/node_esm/dependency_package_outside_project/dependency_package_outside_project.test.mjs +++ b/tests/node_esm/dependency_package_outside_project/dependency_package_outside_project.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -26,8 +26,8 @@ const test = async ({ name, runtime, expectedWarnings }) => { }); importmapFileSnapshot.compare(); const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); + const expect = expectedWarnings; + assert({ actual, expect }); }; // not found for browser runtime diff --git a/tests/node_esm/dependency_package_shared/dependency_package_shared.test.mjs b/tests/node_esm/dependency_package_shared/dependency_package_shared.test.mjs index a2e8e591..50764807 100644 --- a/tests/node_esm/dependency_package_shared/dependency_package_shared.test.mjs +++ b/tests/node_esm/dependency_package_shared/dependency_package_shared.test.mjs @@ -1,7 +1,7 @@ -import { readFileSync } from "node:fs"; -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; import { assert } from "@jsenv/assert"; +import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; +import { takeFileSnapshot } from "@jsenv/snapshot"; +import { readFileSync } from "node:fs"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -55,7 +55,7 @@ const actual = { importMap: importMapNormalized, }), }; -const expected = { +const expect = { bar_inside_project: "http://example.com/node_modules/bar/bar.js", bar_inside_foo: "http://example.com/node_modules/bar/bar.js", node_modules_bar_inside_foo: @@ -66,4 +66,4 @@ const expected = { node_modules_foo_inside_bar: "http://example.com/node_modules/bar/node_modules/foo/foo.js", }; -assert({ actual, expected }); +assert({ actual, expect }); diff --git a/tests/node_esm/dependency_package_shared_indirect/dependency_package_shared_indirect.test.mjs b/tests/node_esm/dependency_package_shared_indirect/dependency_package_shared_indirect.test.mjs index ef3cd360..c269d732 100644 --- a/tests/node_esm/dependency_package_shared_indirect/dependency_package_shared_indirect.test.mjs +++ b/tests/node_esm/dependency_package_shared_indirect/dependency_package_shared_indirect.test.mjs @@ -26,6 +26,6 @@ importmapFileSnapshot.compare(); // importer: `http://example.com/node_modules/bar/bar.js`, // importMap: importMapNormalized, // }) -// const expected = `http://example.com/node_modules/bar/file-inside-bar.js` -// assert({ actual, expected }) +// const expect = `http://example.com/node_modules/bar/file-inside-bar.js` +// assert({ actual, expect }) // } diff --git a/tests/node_esm/dependency_package_syntax_error/dependency_package_syntax_error.test.mjs b/tests/node_esm/dependency_package_syntax_error/dependency_package_syntax_error.test.mjs index bdef7109..5fb3b76b 100644 --- a/tests/node_esm/dependency_package_syntax_error/dependency_package_syntax_error.test.mjs +++ b/tests/node_esm/dependency_package_syntax_error/dependency_package_syntax_error.test.mjs @@ -22,7 +22,7 @@ try { }, }); const actual = errorCalls; - const expected = [ + const expect = [ `error while parsing package.json. --- syntax error message --- Unexpected end of JSON input @@ -32,7 +32,7 @@ ${urlToFileSystemPath( )} `, ]; - assert({ actual, expected }); + assert({ actual, expect }); } finally { console.error = consoleError; } diff --git a/tests/node_esm/dev_and_prod/dev_and_prod.test.mjs b/tests/node_esm/dev_and_prod/dev_and_prod.test.mjs index feab656c..f156a0c5 100644 --- a/tests/node_esm/dev_and_prod/dev_and_prod.test.mjs +++ b/tests/node_esm/dev_and_prod/dev_and_prod.test.mjs @@ -1,23 +1,20 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const devImportmapFileUrl = new URL("./root/dev.importmap", import.meta.url); -const prodImportmapFileUrl = new URL("./root/prod.importmap", import.meta.url); -const devimportmapFileSnapshot = takeFileSnapshot(devImportmapFileUrl); -const prodimportmapFileSnapshot = takeFileSnapshot(prodImportmapFileUrl); -await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "dev.importmap": { - nodeMappings: { - devDependencies: true, +await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "dev.importmap": { + nodeMappings: { + devDependencies: true, + }, + }, + "prod.importmap": {}, }, - }, - "prod.importmap": {}, - }, -}); -devimportmapFileSnapshot.compare(); -prodimportmapFileSnapshot.compare(); + }), + import.meta.url, + `./output/dev_and_prod.md`, +); diff --git a/tests/node_esm/dev_and_prod/root/node_modules/bar/bar.js b/tests/node_esm/dev_and_prod/input/node_modules/bar/bar.js similarity index 100% rename from tests/node_esm/dev_and_prod/root/node_modules/bar/bar.js rename to tests/node_esm/dev_and_prod/input/node_modules/bar/bar.js diff --git a/tests/node_esm/dev_and_prod/root/node_modules/bar/package.json b/tests/node_esm/dev_and_prod/input/node_modules/bar/package.json similarity index 100% rename from tests/node_esm/dev_and_prod/root/node_modules/bar/package.json rename to tests/node_esm/dev_and_prod/input/node_modules/bar/package.json diff --git a/tests/node_esm/dev_and_prod/root/node_modules/foo/foo.js b/tests/node_esm/dev_and_prod/input/node_modules/foo/foo.js similarity index 100% rename from tests/node_esm/dev_and_prod/root/node_modules/foo/foo.js rename to tests/node_esm/dev_and_prod/input/node_modules/foo/foo.js diff --git a/tests/node_esm/dev_and_prod/root/node_modules/foo/package.json b/tests/node_esm/dev_and_prod/input/node_modules/foo/package.json similarity index 100% rename from tests/node_esm/dev_and_prod/root/node_modules/foo/package.json rename to tests/node_esm/dev_and_prod/input/node_modules/foo/package.json diff --git a/tests/node_esm/dev_and_prod/root/package.json b/tests/node_esm/dev_and_prod/input/package.json similarity index 100% rename from tests/node_esm/dev_and_prod/root/package.json rename to tests/node_esm/dev_and_prod/input/package.json diff --git a/tests/node_esm/dev_and_prod/output/dev_and_prod.md b/tests/node_esm/dev_and_prod/output/dev_and_prod.md new file mode 100644 index 00000000..5c4be803 --- /dev/null +++ b/tests/node_esm/dev_and_prod/output/dev_and_prod.md @@ -0,0 +1,55 @@ +1. return promise + +2. write file "input/dev.importmap" +```importmap +{ + "imports": { + "root/": "./", + "bar/": "./node_modules/bar/", + "foo/": "./node_modules/foo/", + "root": "./index", + "bar": "./node_modules/bar/bar.js", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} +} +``` + +3. write file "input/prod.importmap" +```importmap +{ + "imports": { + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} +} +``` + +4. resolve +```js +{ + "dev.importmap": { + "imports": { + "root/": "./", + "bar/": "./node_modules/bar/", + "foo/": "./node_modules/foo/", + "root": "./index", + "bar": "./node_modules/bar/bar.js", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + }, + "prod.importmap": { + "imports": { + "root/": "./", + "foo/": "./node_modules/foo/", + "root": "./index", + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/node_esm/dev_and_prod/root/dev.importmap b/tests/node_esm/dev_and_prod/root/dev.importmap deleted file mode 100644 index 1a5d3342..00000000 --- a/tests/node_esm/dev_and_prod/root/dev.importmap +++ /dev/null @@ -1,11 +0,0 @@ -{ - "imports": { - "root/": "./", - "bar/": "./node_modules/bar/", - "foo/": "./node_modules/foo/", - "root": "./index", - "bar": "./node_modules/bar/bar.js", - "foo": "./node_modules/foo/foo.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/node_esm/dev_and_prod/root/prod.importmap b/tests/node_esm/dev_and_prod/root/prod.importmap deleted file mode 100644 index a537b931..00000000 --- a/tests/node_esm/dev_and_prod/root/prod.importmap +++ /dev/null @@ -1,9 +0,0 @@ -{ - "imports": { - "root/": "./", - "foo/": "./node_modules/foo/", - "root": "./index", - "foo": "./node_modules/foo/foo.js" - }, - "scopes": {} -} \ No newline at end of file diff --git a/tests/node_esm/field_browser_object/field_browser_object.test.mjs b/tests/node_esm/field_browser_object/field_browser_object.test.mjs index ca3e6b25..c2637208 100644 --- a/tests/node_esm/field_browser_object/field_browser_object.test.mjs +++ b/tests/node_esm/field_browser_object/field_browser_object.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -31,7 +31,7 @@ const fooPackageJsonFileUrl = new URL( testDirectoryUrl, ); const actual = warnings; -const expected = [ +const expect = [ { code: "BROWSER_FIELD_NOT_IMPLEMENTED", message: `Found an object "browser" field in a package.json, this is not supported. @@ -51,4 +51,4 @@ Add the following into "packageManualOverrides" As explained in https://github.com/jsenv/importmap-node-module#packagesmanualoverrides`, }, ]; -assert({ actual, expected }); +assert({ actual, expect }); diff --git a/tests/node_esm/field_browser_string/field_browser_string.test.mjs b/tests/node_esm/field_browser_string/field_browser_string.test.mjs index 13d84f6e..6141dea6 100644 --- a/tests/node_esm/field_browser_string/field_browser_string.test.mjs +++ b/tests/node_esm/field_browser_string/field_browser_string.test.mjs @@ -1,6 +1,6 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; import { removeEntrySync, writeFileSync } from "@jsenv/filesystem"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -41,8 +41,8 @@ const test = async ({ name, runtime, expectedWarnings }) => { }); importmapsnapshot.compare(); const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); + const expect = expectedWarnings; + assert({ actual, expect }); }; removeEntrySync(fooBrowserJsFileUrl, { allowUseless: true }); diff --git a/tests/node_esm/field_exports_subpath_mixed/field_exports_subpath_mixed.test.mjs b/tests/node_esm/field_exports_subpath_mixed/field_exports_subpath_mixed.test.mjs index c9f5a9dc..9ba998ff 100644 --- a/tests/node_esm/field_exports_subpath_mixed/field_exports_subpath_mixed.test.mjs +++ b/tests/node_esm/field_exports_subpath_mixed/field_exports_subpath_mixed.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -25,7 +25,7 @@ const fooPackageFileUrl = new URL( import.meta.url, ); const actual = warnings; -const expected = [ +const expect = [ { code: "EXPORTS_SUBPATH_MIXED_KEYS", message: `unexpected keys in package.json exports: cannot mix relative and conditional keys @@ -40,4 +40,4 @@ const expected = [ ${urlToFileSystemPath(fooPackageFileUrl)}`, }, ]; -assert({ actual, expected }); +assert({ actual, expect }); diff --git a/tests/node_esm/field_module/field_module.test.mjs b/tests/node_esm/field_module/field_module.test.mjs index 21576351..d41a4ff5 100644 --- a/tests/node_esm/field_module/field_module.test.mjs +++ b/tests/node_esm/field_module/field_module.test.mjs @@ -1,6 +1,6 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; import { removeEntrySync, writeFileSync } from "@jsenv/filesystem"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -38,8 +38,8 @@ const test = async ({ name, expectedWarnings }) => { }); importmapFileSnapshot.compare(); const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); + const expect = expectedWarnings; + assert({ actual, expect }); }; removeEntrySync(fooModuleJsFileUrl, { allowUseless: true }); diff --git a/tests/node_esm/package_issue_20/package_issue_20.test.mjs b/tests/node_esm/package_issue_20/package_issue_20.test.mjs index c52abd6b..79222d70 100644 --- a/tests/node_esm/package_issue_20/package_issue_20.test.mjs +++ b/tests/node_esm/package_issue_20/package_issue_20.test.mjs @@ -1,7 +1,7 @@ -import { readFileSync } from "node:fs"; -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; import { assert } from "@jsenv/assert"; +import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; +import { takeFileSnapshot } from "@jsenv/snapshot"; +import { readFileSync } from "node:fs"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -28,5 +28,5 @@ const actual = resolveImport({ importer: `http://example.com/node_modules/lume-fake/index.js`, importMap: importMapNormalized, }); -const expected = `http://example.com/node_modules/lume-fake/node_modules/lowclass-fake/dist/index.js`; -assert({ actual, expected }); +const expect = `http://example.com/node_modules/lume-fake/node_modules/lowclass-fake/dist/index.js`; +assert({ actual, expect }); diff --git a/tests/node_esm/react_redux_complex/react_redux_complex.test.mjs b/tests/node_esm/react_redux_complex/react_redux_complex.test.mjs index b068485c..54c2656a 100644 --- a/tests/node_esm/react_redux_complex/react_redux_complex.test.mjs +++ b/tests/node_esm/react_redux_complex/react_redux_complex.test.mjs @@ -1,7 +1,7 @@ -import { readFileSync } from "node:fs"; -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; import { normalizeImportMap, resolveImport } from "@jsenv/importmap"; +import { takeFileSnapshot } from "@jsenv/snapshot"; +import { readFileSync } from "node:fs"; import { writeImportmaps } from "@jsenv/importmap-node-module"; @@ -31,6 +31,5 @@ const actual = resolveImport({ importer: "http://example.com/node_modules/react-redux/es/index.js", importMap: importMapNormalized, }); -const expected = - "http://example.com/node_modules/react-redux/es/utils/answer.js"; -assert({ actual, expected }); +const expect = "http://example.com/node_modules/react-redux/es/utils/answer.js"; +assert({ actual, expect }); diff --git a/tests/node_esm/react_redux_complex/root/start_dev_server.mjs b/tests/node_esm/react_redux_complex/root/start_dev_server.mjs index 1510f7e2..126a25ec 100644 --- a/tests/node_esm/react_redux_complex/root/start_dev_server.mjs +++ b/tests/node_esm/react_redux_complex/root/start_dev_server.mjs @@ -1,4 +1,4 @@ -import { startServer, fetchFileSystem } from "@jsenv/server"; +import { fetchFileSystem, startServer } from "@jsenv/server"; await startServer({ port: 5697, diff --git a/tests/node_esm/root_package_missing/root_package_missing.test.mjs b/tests/node_esm/root_package_missing/root_package_missing.test.mjs index 90bd4a06..284b1be5 100644 --- a/tests/node_esm/root_package_missing/root_package_missing.test.mjs +++ b/tests/node_esm/root_package_missing/root_package_missing.test.mjs @@ -15,9 +15,9 @@ try { throw new Error("should throw"); } catch (e) { const actual = e; - const expected = new Error(`Cannot find root package.json file. + const expect = new Error(`Cannot find root package.json file. --- package.json url --- ${packageFileUrl}`); - expected.code = "PROJECT_PACKAGE_FILE_NOT_FOUND"; - assert({ actual, expected }); + expect.code = "PROJECT_PACKAGE_FILE_NOT_FOUND"; + assert({ actual, expect }); } diff --git a/tests/node_esm/root_package_self_file_dependency/root_package_self_file_dependency.test.mjs b/tests/node_esm/root_package_self_file_dependency/root_package_self_file_dependency.test.mjs index 474c4f91..84cd8400 100644 --- a/tests/node_esm/root_package_self_file_dependency/root_package_self_file_dependency.test.mjs +++ b/tests/node_esm/root_package_self_file_dependency/root_package_self_file_dependency.test.mjs @@ -1,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { removeEntrySync, writeSymbolicLinkSync } from "@jsenv/filesystem"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; diff --git a/tests/snapshot_write_importmaps_side_effects.js b/tests/snapshot_write_importmaps_side_effects.js new file mode 100644 index 00000000..99898ff9 --- /dev/null +++ b/tests/snapshot_write_importmaps_side_effects.js @@ -0,0 +1,15 @@ +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; + +export const snapshotWriteImportsMapsSideEffects = async ( + fn, + fnFileUrl, + sideEffectDirectoryRelativeUrl, + options, +) => { + await snapshotFunctionSideEffects( + fn, + fnFileUrl, + sideEffectDirectoryRelativeUrl, + options, + ); +}; diff --git a/tests/write_inside_html/root/index.html b/tests/write_inside_html/fixtures/0_html_no_importmap/index.html similarity index 100% rename from tests/write_inside_html/root/index.html rename to tests/write_inside_html/fixtures/0_html_no_importmap/index.html diff --git a/tests/write_inside_html/root/main.js b/tests/write_inside_html/fixtures/0_html_no_importmap/main.js similarity index 100% rename from tests/write_inside_html/root/main.js rename to tests/write_inside_html/fixtures/0_html_no_importmap/main.js diff --git a/tests/write_inside_html/root/node_modules/foo/foo.js b/tests/write_inside_html/fixtures/0_html_no_importmap/node_modules/foo/foo.js similarity index 100% rename from tests/write_inside_html/root/node_modules/foo/foo.js rename to tests/write_inside_html/fixtures/0_html_no_importmap/node_modules/foo/foo.js diff --git a/tests/write_inside_html/root/node_modules/foo/package.json b/tests/write_inside_html/fixtures/0_html_no_importmap/node_modules/foo/package.json similarity index 100% rename from tests/write_inside_html/root/node_modules/foo/package.json rename to tests/write_inside_html/fixtures/0_html_no_importmap/node_modules/foo/package.json diff --git a/tests/write_inside_html/root/package.json b/tests/write_inside_html/fixtures/0_html_no_importmap/package.json similarity index 100% rename from tests/write_inside_html/root/package.json rename to tests/write_inside_html/fixtures/0_html_no_importmap/package.json diff --git a/tests/write_inside_html/fixtures/index_importmap_empty.html b/tests/write_inside_html/fixtures/1_html_importmap_empty/index.html similarity index 100% rename from tests/write_inside_html/fixtures/index_importmap_empty.html rename to tests/write_inside_html/fixtures/1_html_importmap_empty/index.html diff --git a/tests/write_inside_html/fixtures/1_html_importmap_empty/main.js b/tests/write_inside_html/fixtures/1_html_importmap_empty/main.js new file mode 100644 index 00000000..c0748305 --- /dev/null +++ b/tests/write_inside_html/fixtures/1_html_importmap_empty/main.js @@ -0,0 +1 @@ +import "foo"; diff --git a/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/foo.js b/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/foo.js new file mode 100644 index 00000000..3c800d3a --- /dev/null +++ b/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/foo.js @@ -0,0 +1 @@ +console.log('foo'); \ No newline at end of file diff --git a/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/package.json b/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/package.json new file mode 100644 index 00000000..d48f02b9 --- /dev/null +++ b/tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/package.json @@ -0,0 +1,5 @@ +{ + "name": "foo", + "main": "./foo.js", + "private": true +} \ No newline at end of file diff --git a/tests/write_inside_html/fixtures/1_html_importmap_empty/package.json b/tests/write_inside_html/fixtures/1_html_importmap_empty/package.json new file mode 100644 index 00000000..3453665e --- /dev/null +++ b/tests/write_inside_html/fixtures/1_html_importmap_empty/package.json @@ -0,0 +1,7 @@ +{ + "name": "root", + "private": true, + "dependencies": { + "foo": "*" + } +} diff --git a/tests/write_inside_html/fixtures/index_importmap_with_src.html b/tests/write_inside_html/fixtures/2_html_importmap_src/index.html similarity index 100% rename from tests/write_inside_html/fixtures/index_importmap_with_src.html rename to tests/write_inside_html/fixtures/2_html_importmap_src/index.html diff --git a/tests/write_inside_html/fixtures/2_html_importmap_src/main.js b/tests/write_inside_html/fixtures/2_html_importmap_src/main.js new file mode 100644 index 00000000..c0748305 --- /dev/null +++ b/tests/write_inside_html/fixtures/2_html_importmap_src/main.js @@ -0,0 +1 @@ +import "foo"; diff --git a/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/foo.js b/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/foo.js new file mode 100644 index 00000000..3c800d3a --- /dev/null +++ b/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/foo.js @@ -0,0 +1 @@ +console.log('foo'); \ No newline at end of file diff --git a/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/package.json b/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/package.json new file mode 100644 index 00000000..d48f02b9 --- /dev/null +++ b/tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/package.json @@ -0,0 +1,5 @@ +{ + "name": "foo", + "main": "./foo.js", + "private": true +} \ No newline at end of file diff --git a/tests/write_inside_html/fixtures/2_html_importmap_src/package.json b/tests/write_inside_html/fixtures/2_html_importmap_src/package.json new file mode 100644 index 00000000..3453665e --- /dev/null +++ b/tests/write_inside_html/fixtures/2_html_importmap_src/package.json @@ -0,0 +1,7 @@ +{ + "name": "root", + "private": true, + "dependencies": { + "foo": "*" + } +} diff --git a/tests/write_inside_html/fixtures/index_without_importmap.html b/tests/write_inside_html/fixtures/index_without_importmap.html deleted file mode 100644 index 964be259..00000000 --- a/tests/write_inside_html/fixtures/index_without_importmap.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Title - - - - - - - - diff --git a/tests/write_inside_html/snapshots/index_without_importmap.html b/tests/write_inside_html/output/0_html_no_importmap.md similarity index 66% rename from tests/write_inside_html/snapshots/index_without_importmap.html rename to tests/write_inside_html/output/0_html_no_importmap.md index 48eada81..ca19bf18 100644 --- a/tests/write_inside_html/snapshots/index_without_importmap.html +++ b/tests/write_inside_html/output/0_html_no_importmap.md @@ -1,3 +1,7 @@ +1. return promise + +2. write file "git_ignored/index.html" +```html @@ -17,4 +21,17 @@ - \ No newline at end of file + +``` + +3. resolve +```js +{ + "index.html": { + "imports": { + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/write_inside_html/snapshots/index_importmap_with_src.html b/tests/write_inside_html/output/1_html_importmap_empty.md similarity index 63% rename from tests/write_inside_html/snapshots/index_importmap_with_src.html rename to tests/write_inside_html/output/1_html_importmap_empty.md index 3368f102..66869774 100644 --- a/tests/write_inside_html/snapshots/index_importmap_with_src.html +++ b/tests/write_inside_html/output/1_html_importmap_empty.md @@ -1,3 +1,7 @@ +1. return promise + +2. write file "git_ignored/index.html" +```html @@ -17,4 +21,17 @@ - \ No newline at end of file + +``` + +3. resolve +```js +{ + "index.html": { + "imports": { + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/write_inside_html/snapshots/index_importmap_empty.html b/tests/write_inside_html/output/2_html_importmap_src.md similarity index 54% rename from tests/write_inside_html/snapshots/index_importmap_empty.html rename to tests/write_inside_html/output/2_html_importmap_src.md index 3368f102..a4260ab3 100644 --- a/tests/write_inside_html/snapshots/index_importmap_empty.html +++ b/tests/write_inside_html/output/2_html_importmap_src.md @@ -1,3 +1,12 @@ +1. return promise + +2. console.warn +```console +remove src=./project.importmap from - \ No newline at end of file + +``` + +4. resolve +```js +{ + "index.html": { + "imports": { + "foo": "./node_modules/foo/foo.js" + }, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/write_inside_html/write_inside_html.test.mjs b/tests/write_inside_html/write_inside_html.test.mjs index 3fd2f055..a6ddcaf9 100644 --- a/tests/write_inside_html/write_inside_html.test.mjs +++ b/tests/write_inside_html/write_inside_html.test.mjs @@ -1,39 +1,26 @@ -import { takeDirectorySnapshot } from "@jsenv/snapshot"; -import { copyFileSync } from "@jsenv/filesystem"; - +import { writeFileStructureSync } from "@jsenv/filesystem"; import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; -const testDirectoryUrl = new URL("./root/", import.meta.url); -const snapshotDirectoryUrl = new URL("./snapshots/", import.meta.url); - -const test = async (fixtureName, options) => { - copyFileSync({ - from: new URL(`./fixtures/${fixtureName}`, import.meta.url), - to: new URL("./root/index.html", import.meta.url), - overwrite: true, - }); - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - "./index.html": {}, - }, - ...options, - }); - copyFileSync({ - from: new URL("./root/index.html", import.meta.url), - to: new URL(`./snapshots/${fixtureName}`, import.meta.url), - overwrite: true, - }); - copyFileSync({ - from: new URL(`./fixtures/${fixtureName}`, import.meta.url), - to: new URL("./root/index.html", import.meta.url), - overwrite: true, - }); +const test = async (scenario, options) => { + writeFileStructureSync( + new URL("./git_ignored/", import.meta.url), + new URL(`./fixtures/${scenario}/`, import.meta.url), + ); + await snapshotWriteImportsMapsSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./git_ignored/", import.meta.url), + importmaps: { + "index.html": {}, + }, + ...options, + }), + import.meta.url, + `./output/${scenario}.md`, + ); }; - -const directorySnapshot = takeDirectorySnapshot(snapshotDirectoryUrl); -await test("index_importmap_empty.html"); -await test("index_importmap_with_src.html", { logLevel: "error" }); -await test("index_without_importmap.html"); -directorySnapshot.compare(); +await test("0_html_no_importmap"); +await test("1_html_importmap_empty", { logLevel: "error" }); +await test("2_html_importmap_src");