From f7cd074a025d0eabf6d6cd5e44ae65299afa0729 Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 09:30:36 +0200 Subject: [PATCH 01/33] update deps + run prettier --- .../workflows/report_performance_impact.mjs | 2 +- .prettierrc.yml | 2 + experiment/getImportMapFromFile.js | 2 +- experiment/lit_typescript/dist/index.js | 2 +- experiment/lit_typescript/index.ts | 2 +- package.json | 47 ++++++++++--------- src/cli.mjs | 2 +- src/step_entry_point/html_parser.js | 10 ++-- src/step_entry_point/js_parser.js | 2 +- .../test_importmap_on_entry_points.js | 28 +++++------ src/step_node_esm/node_module_resolution.js | 8 ++-- src/step_node_esm/resolve_package_main.js | 2 +- .../visit_node_module_resolution.js | 8 ++-- src/step_node_esm/visit_package_exports.js | 2 +- src/step_node_esm/visit_package_importmap.js | 2 +- src/step_write_into_files/write_into_files.js | 10 ++-- src/util/logs.js | 2 +- src/write_importmaps.js | 6 +-- tests/__internal__/js_parser.test.mjs | 2 +- .../updating_jsconfig_react.test.mjs | 2 +- .../auto_mapping_bare_specifier.test.mjs | 2 +- ...ping_extensionless_in_node_module.test.mjs | 2 +- .../auto_mapping_lodash.test.mjs | 2 +- .../entry_point_file_not_found.test.mjs | 2 +- .../entry_point_many_2.test.mjs | 2 +- .../js_import_fs/js_import_fs.test.mjs | 2 +- .../js_import_leading_slash.test.mjs | 2 +- .../root/index.js | 4 +- .../dependency_package_inside.test.mjs | 4 +- .../dependency_package_many/root/index.js | 2 +- .../dependency_package_missing.test.mjs | 2 +- ...ependency_package_outside_project.test.mjs | 2 +- .../dependency_package_shared.test.mjs | 6 +-- .../field_browser_object.test.mjs | 2 +- .../field_browser_string.test.mjs | 2 +- .../field_exports_subpath_mixed.test.mjs | 2 +- .../field_module/field_module.test.mjs | 2 +- .../package_issue_20.test.mjs | 6 +-- .../react_redux_complex.test.mjs | 4 +- .../root/start_dev_server.mjs | 2 +- ...root_package_self_file_dependency.test.mjs | 2 +- .../write_inside_html.test.mjs | 2 +- 42 files changed, 102 insertions(+), 99 deletions(-) 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/.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..f66d0046 100644 --- a/package.json +++ b/package.json @@ -30,39 +30,40 @@ ], "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.5", + "@jsenv/filesystem": "4.8.2", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", - "@jsenv/urls": "2.2.1" + "@jsenv/urls": "2.3.1" }, "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.5", "@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.3", + "@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.14", + "@jsenv/snapshot": "2.1.1", + "@jsenv/test": "3.3.13", + "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/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..29433bd5 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, 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/write_importmaps.js b/src/write_importmaps.js index a1bedd5b..9e639aa6 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 = { diff --git a/tests/__internal__/js_parser.test.mjs b/tests/__internal__/js_parser.test.mjs index fc9dbcc4..299232d2 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"; 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..af1b7e94 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,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; 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..a6fc6222 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,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"; 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..a87ef8a0 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,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"; 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..efd75ce6 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,5 +1,5 @@ import { assert } from "@jsenv/assert"; -import { writeFileSync, removeFileSync } from "@jsenv/filesystem"; +import { removeFileSync, writeFileSync } from "@jsenv/filesystem"; import { urlToFileSystemPath } from "@jsenv/urls"; import { writeImportmaps } from "@jsenv/importmap-node-module"; 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..a6d87d85 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,5 +1,5 @@ -import { takeDirectorySnapshot } from "@jsenv/snapshot"; import { copyFileSync } from "@jsenv/filesystem"; +import { takeDirectorySnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; 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..eb0eb116 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,5 +1,5 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; import { assert } from "@jsenv/assert"; +import { takeFileSnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; 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..8aea5f65 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,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"; 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/root/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/root/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/node_esm/dependency_package_inside/dependency_package_inside.test.mjs b/tests/node_esm/dependency_package_inside/dependency_package_inside.test.mjs index 93be52b0..7edf0545 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"; 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..75a406ac 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"; 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..87cc8c74 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"; 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..c4aa5fb5 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"; 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..a18f228e 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"; 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..cd412742 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"; 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..d388c5cf 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"; diff --git a/tests/node_esm/field_module/field_module.test.mjs b/tests/node_esm/field_module/field_module.test.mjs index 21576351..448fe39c 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"; 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..e1ba3ad5 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"; 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..e53f7635 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"; 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_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/write_inside_html/write_inside_html.test.mjs b/tests/write_inside_html/write_inside_html.test.mjs index 3fd2f055..5eb837be 100644 --- a/tests/write_inside_html/write_inside_html.test.mjs +++ b/tests/write_inside_html/write_inside_html.test.mjs @@ -1,5 +1,5 @@ -import { takeDirectorySnapshot } from "@jsenv/snapshot"; import { copyFileSync } from "@jsenv/filesystem"; +import { takeDirectorySnapshot } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; From b9539c7a7912623b180feb588424e94671b42b2d Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 09:31:54 +0200 Subject: [PATCH 02/33] update expected to expect --- scripts/test.mjs | 2 -- .../import_map_to_vs_code_config_paths.test.mjs | 4 ++-- tests/__internal__/js_parser.test.mjs | 16 ++++++++-------- .../auto_mapping_bare_specifier.test.mjs | 4 ++-- ...mapping_extensionless_in_node_module.test.mjs | 4 ++-- .../auto_mapping_lodash.test.mjs | 2 +- .../entry_point_file_not_found.test.mjs | 8 ++++---- .../js_import_fs/js_import_fs.test.mjs | 4 ++-- .../js_import_leading_slash.test.mjs | 4 ++-- .../dependency_package_inside.test.mjs | 4 ++-- .../dependency_package_missing.test.mjs | 4 ++-- .../dependency_package_outside_project.test.mjs | 4 ++-- .../dependency_package_shared.test.mjs | 4 ++-- .../dependency_package_shared_indirect.test.mjs | 4 ++-- .../dependency_package_syntax_error.test.mjs | 4 ++-- .../field_browser_object.test.mjs | 4 ++-- .../field_browser_string.test.mjs | 4 ++-- .../field_exports_subpath_mixed.test.mjs | 4 ++-- .../node_esm/field_module/field_module.test.mjs | 4 ++-- .../package_issue_20/package_issue_20.test.mjs | 4 ++-- .../react_redux_complex.test.mjs | 5 ++--- .../root_package_missing.test.mjs | 6 +++--- 22 files changed, 50 insertions(+), 53 deletions(-) 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/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 299232d2..5060a3ae 100644 --- a/tests/__internal__/js_parser.test.mjs +++ b/tests/__internal__/js_parser.test.mjs @@ -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/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 af1b7e94..b01b52c1 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 @@ -31,7 +31,7 @@ const test = async ({ bareSpecifierAutomapping }) => { }); importmapFileSnapshot.compare(); const actual = warnings; - const expected = bareSpecifierAutomapping + const expect = bareSpecifierAutomapping ? [] : [ { @@ -58,7 +58,7 @@ add mapping to "manualImportmap" }`, }, ]; - assert({ actual, expected }); + assert({ actual, expect }); return { warnings }; }; 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 a6fc6222..11c2d989 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 @@ -31,8 +31,8 @@ const test = async ({ name, magicExtensions, expectedWarnings }) => { }); importmapFileSnapshot.compare(); const actual = warnings; - const expected = expectedWarnings; - assert({ actual, expected }); + const expect = expectedWarnings; + assert({ actual, expect }); }; await test({ 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 a87ef8a0..257c32a4 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 @@ -38,7 +38,7 @@ const test = async ({ name, magicExtensions, expectedWarnings } = {}) => { importmapFileSnapshot.compare(); assert({ actual: warnings, - expected: expectedWarnings, + expect: expectedWarnings, }); }; 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 efd75ce6..6a91e41c 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 @@ -28,7 +28,7 @@ const getWarnings = async () => { removeFileSync(mainJsFileUrl, { allowUseless: true }); { const actual = await getWarnings(); - const expected = [ + const expect = [ { code: "IMPORT_RESOLUTION_FAILED", message: `Import resolution failed for "./main.js" @@ -40,12 +40,12 @@ file not found on filesystem at ${urlToFileSystemPath( )}`, }, ]; - assert({ actual, expected }); + assert({ actual, expect }); } writeFileSync(mainJsFileUrl); { const actual = await getWarnings(); - const expected = []; - assert({ actual, expected }); + const expect = []; + assert({ actual, expect }); } 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 eb0eb116..718f0650 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 @@ -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 }); }; await test({ 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 8aea5f65..0c8bdf69 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 @@ -32,7 +32,7 @@ const test = async ({ name, runtime }) => { }); importmapFileSnapshot.compare(); const actual = warnings; - const expected = + const expect = runtime === "node" ? [ { @@ -49,7 +49,7 @@ file not found on filesystem at ${urlToFileSystemPath("file:///foo.js")}`, }, ] : []; - assert({ actual, expected }); + assert({ actual, expect }); }; await test({ 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 7edf0545..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 @@ -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_missing/dependency_package_missing.test.mjs b/tests/node_esm/dependency_package_missing/dependency_package_missing.test.mjs index 75a406ac..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 @@ -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 87cc8c74..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 @@ -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 c4aa5fb5..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 @@ -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/field_browser_object/field_browser_object.test.mjs b/tests/node_esm/field_browser_object/field_browser_object.test.mjs index a18f228e..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 @@ -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 cd412742..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 @@ -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 d388c5cf..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 @@ -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 448fe39c..d41a4ff5 100644 --- a/tests/node_esm/field_module/field_module.test.mjs +++ b/tests/node_esm/field_module/field_module.test.mjs @@ -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 e1ba3ad5..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 @@ -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 e53f7635..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 @@ -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/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 }); } From b3fe6a4d0b9a67e4d92fbe55c525b58e6918c7fe Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 10:02:09 +0200 Subject: [PATCH 03/33] small fix --- package.json | 2 +- src/step_write_into_files/write_into_files.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f66d0046..88db32cf 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", "@jsenv/snapshot": "2.1.1", - "@jsenv/test": "3.3.13", + "@jsenv/test": "3.3.14", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", diff --git a/src/step_write_into_files/write_into_files.js b/src/step_write_into_files/write_into_files.js index 29433bd5..be08facf 100644 --- a/src/step_write_into_files/write_into_files.js +++ b/src/step_write_into_files/write_into_files.js @@ -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, { From bf6d028f9d849bd4cbe4ccac3133cb50540e6551 Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 10:53:02 +0200 Subject: [PATCH 04/33] rename a dir --- .../auto_mapping_bare_specifier/{root => input}/file.js | 0 .../auto_mapping_bare_specifier/{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../auto_mapping_bare_specifier/root/test.importmap | 4 ---- .../root/test_base_automapping.importmap | 6 ------ 5 files changed, 10 deletions(-) rename tests/entry_point_check/auto_mapping_bare_specifier/{root => input}/file.js (100%) rename tests/entry_point_check/auto_mapping_bare_specifier/{root => input}/index.js (100%) rename tests/entry_point_check/auto_mapping_bare_specifier/{root => input}/package.json (100%) delete mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/root/test.importmap delete mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/root/test_base_automapping.importmap 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/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 From fa40f8915d8acf5387c87178a8f5119bb26cf0de Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 10:59:12 +0200 Subject: [PATCH 05/33] prepare introduction of takeExecutionSnapshot --- .eslintignore | 1 + package.json | 2 +- .../auto_mapping_bare_specifier.test.mjs | 177 ++++++++++++------ 3 files changed, 121 insertions(+), 59 deletions(-) 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/package.json b/package.json index 88db32cf..c310403f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", "@jsenv/ast": "6.2.5", - "@jsenv/filesystem": "4.8.2", + "@jsenv/filesystem": "4.9.0", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", "@jsenv/urls": "2.3.1" 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 b01b52c1..d8f6bb67 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,128 @@ -import { assert } from "@jsenv/assert"; -import { takeFileSnapshot } from "@jsenv/snapshot"; +import { + replaceFluctuatingValues, + takeDirectorySnapshot, +} from "@jsenv/snapshot"; +import { moveEntrySync, writeFileSync } from "@jsenv/filesystem"; import { writeImportmaps } from "@jsenv/importmap-node-module"; -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}`, - import.meta.url, - ); - 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 expect = bareSpecifierAutomapping - ? [] - : [ +const takeExecutionSnapshot = ( + fn, + outputDirectoryUrl, + { rootDirectoryUrl, captureConsole = true, filesystemRedirects } = {}, +) => { + const outputDirectorySnapshot = takeDirectorySnapshot(outputDirectoryUrl); + const finallyCallbackSet = new Set(); + + const errorFileUrl = new URL("./error.txt", import.meta.url); + const resultFileUrl = new URL("./result.json", import.meta.url); + const onError = (e) => { + writeFileSync( + errorFileUrl, + replaceFluctuatingValues(e.stack, { + fileUrl: errorFileUrl, + }), + ); + }; + const onResult = (result) => { + if (result === undefined) { + return; + } + writeFileSync( + resultFileUrl, + replaceFluctuatingValues(JSON.stringify(result, null, " "), { + fileUrl: resultFileUrl, + rootDirectoryUrl, + }), + ); + }; + if (captureConsole) { + const warningsFileUrl = new URL("./warnings.txt", import.meta.url); + const { warn } = console; + let warnings = ""; + console.warn = (message) => { + if (warnings) { + warnings += "\n"; + } + warnings += message; + }; + finallyCallbackSet.add(() => { + console.warn = warn; + if (warnings) { + writeFileSync( + warningsFileUrl, + replaceFluctuatingValues(warnings, { + fileUrl: warningsFileUrl, + rootDirectoryUrl, + }), + ); + } + }); + } + if (filesystemRedirects) { + for (const filesystemRedirect of filesystemRedirects) { + finallyCallbackSet.add(() => { { - 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" + moveEntrySync({ + from: filesystemRedirect.from, + to: filesystemRedirect.into, + noEntryEffect: "none", + }); + } + }); + } } -}`, + try { + const returnValue = fn(); + if (returnValue && returnValue.then) { + returnValue.then( + (value) => { + onResult(value); }, - ]; - assert({ actual, expect }); + (e) => { + onError(e); + }, + ); + } else { + onResult(returnValue); + } + } catch (e) { + onError(e); + } finally { + for (const finallyCallback of finallyCallbackSet) { + finallyCallback(); + } + outputDirectorySnapshot.compare(); + } +}; - return { warnings }; +const test = async (scenario, { bareSpecifierAutomapping }) => { + await takeExecutionSnapshot( + async () => { + await writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + [`${scenario}.importmap`]: { + importResolution: { + entryPoints: ["./index.js"], + bareSpecifierAutomapping, + }, + }, + }, + }); + }, + new URL(`./output/${scenario}/`, import.meta.url), + { + filesystemRedirects: [ + { + from: new URL(`./input/${scenario}.importmap`, import.meta.url), + into: new URL(`./output/${scenario}.importmap`, import.meta.url), + }, + ], + }, + ); }; -await test({}); -await test({ bareSpecifierAutomapping: true }); +await test("default", {}); +await test("bare_specifier_automapping", { bareSpecifierAutomapping: true }); From 78a80de2796a1f19c1e774397f4d1c267d16dffd Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 13:10:24 +0200 Subject: [PATCH 06/33] use snapshotFunctionSideEffects --- package.json | 8 +- .../auto_mapping_bare_specifier.test.mjs | 114 ++---------------- .../output/0_default/side_effect.txt | 8 ++ .../side_effect.txt | 34 ++++++ 4 files changed, 55 insertions(+), 109 deletions(-) create mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt create mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt diff --git a/package.json b/package.json index c310403f..dc7a7d3a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", "@jsenv/ast": "6.2.5", - "@jsenv/filesystem": "4.9.0", + "@jsenv/filesystem": "4.9.1", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", "@jsenv/urls": "2.3.1" @@ -51,15 +51,15 @@ "@babel/plugin-syntax-jsx": "7.24.7", "@jsenv/assert": "4.1.5", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.3", + "@jsenv/core": "39.2.5", "@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.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.1.1", - "@jsenv/test": "3.3.14", + "@jsenv/snapshot": "2.2.5", + "@jsenv/test": "3.3.16", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", 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 d8f6bb67..fbe78ff5 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,103 +1,9 @@ -import { - replaceFluctuatingValues, - takeDirectorySnapshot, -} from "@jsenv/snapshot"; +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; -import { moveEntrySync, writeFileSync } from "@jsenv/filesystem"; import { writeImportmaps } from "@jsenv/importmap-node-module"; -const takeExecutionSnapshot = ( - fn, - outputDirectoryUrl, - { rootDirectoryUrl, captureConsole = true, filesystemRedirects } = {}, -) => { - const outputDirectorySnapshot = takeDirectorySnapshot(outputDirectoryUrl); - const finallyCallbackSet = new Set(); - - const errorFileUrl = new URL("./error.txt", import.meta.url); - const resultFileUrl = new URL("./result.json", import.meta.url); - const onError = (e) => { - writeFileSync( - errorFileUrl, - replaceFluctuatingValues(e.stack, { - fileUrl: errorFileUrl, - }), - ); - }; - const onResult = (result) => { - if (result === undefined) { - return; - } - writeFileSync( - resultFileUrl, - replaceFluctuatingValues(JSON.stringify(result, null, " "), { - fileUrl: resultFileUrl, - rootDirectoryUrl, - }), - ); - }; - if (captureConsole) { - const warningsFileUrl = new URL("./warnings.txt", import.meta.url); - const { warn } = console; - let warnings = ""; - console.warn = (message) => { - if (warnings) { - warnings += "\n"; - } - warnings += message; - }; - finallyCallbackSet.add(() => { - console.warn = warn; - if (warnings) { - writeFileSync( - warningsFileUrl, - replaceFluctuatingValues(warnings, { - fileUrl: warningsFileUrl, - rootDirectoryUrl, - }), - ); - } - }); - } - if (filesystemRedirects) { - for (const filesystemRedirect of filesystemRedirects) { - finallyCallbackSet.add(() => { - { - moveEntrySync({ - from: filesystemRedirect.from, - to: filesystemRedirect.into, - noEntryEffect: "none", - }); - } - }); - } - } - try { - const returnValue = fn(); - if (returnValue && returnValue.then) { - returnValue.then( - (value) => { - onResult(value); - }, - (e) => { - onError(e); - }, - ); - } else { - onResult(returnValue); - } - } catch (e) { - onError(e); - } finally { - for (const finallyCallback of finallyCallbackSet) { - finallyCallback(); - } - outputDirectorySnapshot.compare(); - } -}; - const test = async (scenario, { bareSpecifierAutomapping }) => { - await takeExecutionSnapshot( + await snapshotFunctionSideEffects( async () => { await writeImportmaps({ logLevel: "warn", @@ -112,17 +18,15 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { }, }); }, - new URL(`./output/${scenario}/`, import.meta.url), + import.meta.url, + `./output/${scenario}/`, { - filesystemRedirects: [ - { - from: new URL(`./input/${scenario}.importmap`, import.meta.url), - into: new URL(`./output/${scenario}.importmap`, import.meta.url), - }, - ], + filesystemEffects: [`./input/${scenario}.importmap`], + restoreFilesystem: true, + filesystemEffectsInline: true, }, ); }; -await test("default", {}); -await test("bare_specifier_automapping", { bareSpecifierAutomapping: true }); +await test("0_default", {}); +await test("1_bare_specifier_automapping", { bareSpecifierAutomapping: true }); diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt new file mode 100644 index 00000000..781b4685 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt @@ -0,0 +1,8 @@ +1. write file "input/0_default.importmap" +{ + "imports": {}, + "scopes": {} +} + +2. return +undefined \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt new file mode 100644 index 00000000..5231e7ff --- /dev/null +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt @@ -0,0 +1,34 @@ +1. console.warn + +Import resolution failed for "file" +--- import trace --- +file:///cwd()/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" + } +} + + +2. write file "input/1_bare_specifier_automapping.importmap" +{ + "imports": { + "file": "./file.js" + }, + "scopes": {} +} + +3. return +undefined \ No newline at end of file From 4f053d28acd8d7a772abd5258d52c6cf0cb9d804 Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 13:14:18 +0200 Subject: [PATCH 07/33] use more of snapshotFunctionSideEffects --- .../auto_mapping_bare_specifier.test.mjs | 7 ++-- .../output/0_default/side_effect.txt | 7 +++- .../side_effect.txt | 9 +++- .../auto_mapping_css_to_js.test.mjs | 41 +++++++++++-------- .../{root => input}/file.css.js | 0 .../{root => input}/main.js | 0 .../{root => input}/package.json | 0 .../output/side_effect.txt | 17 ++++++++ .../root/test.importmap | 6 --- 9 files changed, 59 insertions(+), 28 deletions(-) rename tests/entry_point_check/auto_mapping_css_to_js/{root => input}/file.css.js (100%) rename tests/entry_point_check/auto_mapping_css_to_js/{root => input}/main.js (100%) rename tests/entry_point_check/auto_mapping_css_to_js/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/auto_mapping_css_to_js/output/side_effect.txt delete mode 100644 tests/entry_point_check/auto_mapping_css_to_js/root/test.importmap 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 fbe78ff5..e0749e38 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 @@ -4,8 +4,8 @@ import { writeImportmaps } from "@jsenv/importmap-node-module"; const test = async (scenario, { bareSpecifierAutomapping }) => { await snapshotFunctionSideEffects( - async () => { - await writeImportmaps({ + () => + writeImportmaps({ logLevel: "warn", directoryUrl: new URL("./input/", import.meta.url), importmaps: { @@ -16,8 +16,7 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { }, }, }, - }); - }, + }), import.meta.url, `./output/${scenario}/`, { diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt index 781b4685..ddd1a21b 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt @@ -5,4 +5,9 @@ } 2. return -undefined \ No newline at end of file +{ + "0_default.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/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt index 5231e7ff..458b9dcf 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt @@ -31,4 +31,11 @@ add mapping to "manualImportmap" } 3. return -undefined \ No newline at end of file +{ + "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_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..734030c3 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,29 @@ -import { takeFileSnapshot } from "@jsenv/snapshot"; +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; import { writeImportmaps } from "@jsenv/importmap-node-module"; -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"], - }, +const test = async () => { + await snapshotFunctionSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + magicExtensions: ["inherit"], + }, + }, + }, + }), + import.meta.url, + `./output/`, + { + filesystemEffects: [`./input/test.importmap`], + restoreFilesystem: true, + filesystemEffectsInline: true, }, - }, -}); -importmapFileSnapshot.compare(); + ); +}; +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/side_effect.txt b/tests/entry_point_check/auto_mapping_css_to_js/output/side_effect.txt new file mode 100644 index 00000000..4e4a67e7 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_css_to_js/output/side_effect.txt @@ -0,0 +1,17 @@ +1. write file "input/test.importmap" +{ + "imports": { + "./file.css": "./file.css.js" + }, + "scopes": {} +} + +2. return +{ + "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 From c8fefac8f93a821f189bcbf07190c0d7a61cacdc Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 13:32:40 +0200 Subject: [PATCH 08/33] update deps --- package.json | 12 +- .../auto_mapping_css_to_js.test.mjs | 3 +- ...ping_extensionless_in_node_module.test.mjs | 107 +++++------------- .../{root => input}/main.js | 0 .../node_modules/leftpad/file.js | 0 .../node_modules/leftpad/index.js | 0 .../node_modules/leftpad/other-file.ts | 0 .../node_modules/leftpad/package.json | 0 .../{root => input}/package.json | 0 .../0_default/0_default_side_effects.txt | 17 +++ .../1_magic_extensions_js_side_effects.txt | 25 ++++ ..._magic_extensions_inherit_side_effects.txt | 51 +++++++++ .../root/default.importmap | 6 - .../root/magic_extensions_inherit.importmap | 11 -- .../root/magic_extensions_js.importmap | 10 -- 15 files changed, 126 insertions(+), 116 deletions(-) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/main.js (100%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/node_modules/leftpad/file.js (100%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/node_modules/leftpad/index.js (100%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/node_modules/leftpad/other-file.ts (100%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/node_modules/leftpad/package.json (100%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt create mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt create mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt delete mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/default.importmap delete mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_inherit.importmap delete mode 100644 tests/entry_point_check/auto_mapping_extensionless_in_node_module/root/magic_extensions_js.importmap diff --git a/package.json b/package.json index dc7a7d3a..32923b45 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,11 @@ "dependencies": { "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", - "@jsenv/ast": "6.2.5", - "@jsenv/filesystem": "4.9.1", + "@jsenv/ast": "6.2.6", + "@jsenv/filesystem": "4.9.2", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", - "@jsenv/urls": "2.3.1" + "@jsenv/urls": "2.3.2" }, "devDependencies": { "@babel/eslint-parser": "7.24.8", @@ -51,15 +51,15 @@ "@babel/plugin-syntax-jsx": "7.24.7", "@jsenv/assert": "4.1.5", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.5", + "@jsenv/core": "39.2.6", "@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.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.2.5", - "@jsenv/test": "3.3.16", + "@jsenv/snapshot": "2.2.6", + "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", 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 734030c3..8dfd493a 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,6 +1,5 @@ -import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; const test = async () => { await snapshotFunctionSideEffects( 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 11c2d989..ded8ea65 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,37 @@ -import { assert } from "@jsenv/assert"; -import { takeFileSnapshot } from "@jsenv/snapshot"; -import { urlToFileSystemPath } from "@jsenv/urls"; - import { writeImportmaps } from "@jsenv/importmap-node-module"; +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; -const testDirectoryUrl = new URL("./root/", import.meta.url); - -const test = async ({ name, magicExtensions, expectedWarnings }) => { - const importmapRelativeUrl = `${name}.importmap`; - const importmapFileUrl = new URL( - `./root/${importmapRelativeUrl}`, - import.meta.url, - ); - const importmapFileSnapshot = takeFileSnapshot(importmapFileUrl); - const warnings = []; - await writeImportmaps({ - logLevel: "warn", - directoryUrl: testDirectoryUrl, - importmaps: { - [importmapRelativeUrl]: { - importResolution: { - entryPoints: ["./main.js"], - magicExtensions, +const test = async (scenario, { magicExtensions } = {}) => { + await snapshotFunctionSideEffects( + () => + writeImportmaps({ + logLevel: "warn", + directoryUrl: new URL("./input/", import.meta.url), + importmaps: { + "test.importmap": { + importResolution: { + entryPoints: ["./main.js"], + magicExtensions, + }, + }, }, - }, - }, - onWarn: (warning) => { - warnings.push(warning); + }), + import.meta.url, + `./output/${scenario}/`, + { + filesystemEffects: [`./input/test.importmap`], + restoreFilesystem: true, + filesystemEffectsInline: true, }, - }); - importmapFileSnapshot.compare(); - const actual = warnings; - const expect = expectedWarnings; - assert({ actual, expect }); + ); }; -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_default", { + 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_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt new file mode 100644 index 00000000..fbaa4123 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt @@ -0,0 +1,17 @@ +1. write file "input/test.importmap" +{ + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": {} +} + +2. return +{ + "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/1_magic_extensions_js_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt new file mode 100644 index 00000000..3c4a7af3 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt @@ -0,0 +1,25 @@ +1. write file "input/test.importmap" +{ + "imports": { + "leftpad": "./node_modules/leftpad/index.js" + }, + "scopes": { + "./node_modules/leftpad/": { + "./node_modules/leftpad/file": "./node_modules/leftpad/file.js" + } + } +} + +2. return +{ + "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/2_magic_extensions_inherit_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt new file mode 100644 index 00000000..337a4d01 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt @@ -0,0 +1,51 @@ +1. console.warn + +Import resolution failed for "./file" +--- import trace --- +file:///cwd()/input/node_modules/leftpad/index.js:1:7 +> 1 | import "./file" + | ^ +--- reason --- +file not found on filesystem at cwd()/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" + } + } +} + + +2. write file "input/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" + } + } +} + +3. return +{ + "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 From f3ebad651ff883daca227ce0a9be80c90ee539c0 Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 13:56:28 +0200 Subject: [PATCH 09/33] update snapshot after updating snapshotFunctionSideEffects --- package.json | 2 +- src/write_importmaps.js | 2 +- .../auto_mapping_bare_specifier.test.mjs | 9 ++++-- .../0_default_side_effects.txt} | 12 +++----- .../output/0_default/side_effect.txt | 13 --------- ...are_specifier_automapping_side_effects.txt | 17 +++++++++++ ...ide_effect.txt => output_side_effects.txt} | 0 .../0_default/0_default_side_effects.txt | 28 +++++++++++++++++-- .../1_magic_extensions_js_side_effects.txt | 15 ++++++++-- ..._magic_extensions_inherit_side_effects.txt | 28 ++----------------- 10 files changed, 70 insertions(+), 56 deletions(-) rename tests/entry_point_check/auto_mapping_bare_specifier/output/{1_bare_specifier_automapping/side_effect.txt => 0_default/0_default_side_effects.txt} (72%) delete mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt create mode 100644 tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt rename tests/entry_point_check/auto_mapping_css_to_js/output/{side_effect.txt => output_side_effects.txt} (100%) diff --git a/package.json b/package.json index 32923b45..4ff9706e 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@jsenv/package-publish": "1.10.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.2.6", + "@jsenv/snapshot": "2.2.7", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", diff --git a/src/write_importmaps.js b/src/write_importmaps.js index 9e639aa6..daf499cd 100644 --- a/src/write_importmaps.js +++ b/src/write_importmaps.js @@ -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/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 e0749e38..33177b29 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 @@ -21,11 +21,14 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { `./output/${scenario}/`, { filesystemEffects: [`./input/${scenario}.importmap`], - restoreFilesystem: true, filesystemEffectsInline: true, }, ); }; -await test("0_default", {}); -await test("1_bare_specifier_automapping", { bareSpecifierAutomapping: true }); +await test("0_default", { + bareSpecifierAutomapping: undefined, +}); +await test("1_bare_specifier_automapping", { + bareSpecifierAutomapping: true, +}); diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt similarity index 72% rename from tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt rename to tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt index 458b9dcf..3524ca31 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/side_effect.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt @@ -22,20 +22,16 @@ add mapping to "manualImportmap" } -2. write file "input/1_bare_specifier_automapping.importmap" +2. write file "input/0_default.importmap" { - "imports": { - "file": "./file.js" - }, + "imports": {}, "scopes": {} } 3. return { - "1_bare_specifier_automapping.importmap": { - "imports": { - "file": "./file.js" - }, + "0_default.importmap": { + "imports": {}, "scopes": {} } } \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt deleted file mode 100644 index ddd1a21b..00000000 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/side_effect.txt +++ /dev/null @@ -1,13 +0,0 @@ -1. write file "input/0_default.importmap" -{ - "imports": {}, - "scopes": {} -} - -2. return -{ - "0_default.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/1_bare_specifier_automapping_side_effects.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt new file mode 100644 index 00000000..555b3664 --- /dev/null +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt @@ -0,0 +1,17 @@ +1. write file "input/1_bare_specifier_automapping.importmap" +{ + "imports": { + "file": "./file.js" + }, + "scopes": {} +} + +2. return +{ + "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_css_to_js/output/side_effect.txt b/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt similarity index 100% rename from tests/entry_point_check/auto_mapping_css_to_js/output/side_effect.txt rename to tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt index fbaa4123..22624a2e 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt @@ -1,4 +1,28 @@ -1. write file "input/test.importmap" +1. console.warn + +Import resolution failed for "./file" +--- import trace --- +file:///cwd()/input/node_modules/leftpad/index.js:1:7 +> 1 | import "./file" + | ^ +--- reason --- +file not found on filesystem at cwd()/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" + } + } +} + + +2. write file "input/test.importmap" { "imports": { "leftpad": "./node_modules/leftpad/index.js" @@ -6,7 +30,7 @@ "scopes": {} } -2. return +3. return { "test.importmap": { "imports": { diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt index 3c4a7af3..e33c3972 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt @@ -1,4 +1,15 @@ -1. write file "input/test.importmap" +1. console.warn + +Import resolution failed for "./other-file" +--- import trace --- +file:///cwd()/input/node_modules/leftpad/file.js:1:7 +> 1 | import "./other-file" + | ^ +--- reason --- +file not found on filesystem at cwd()/input/node_modules/leftpad/other-file + + +2. write file "input/test.importmap" { "imports": { "leftpad": "./node_modules/leftpad/index.js" @@ -10,7 +21,7 @@ } } -2. return +3. return { "test.importmap": { "imports": { diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt index 337a4d01..ce3d8ad8 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt @@ -1,28 +1,4 @@ -1. console.warn - -Import resolution failed for "./file" ---- import trace --- -file:///cwd()/input/node_modules/leftpad/index.js:1:7 -> 1 | import "./file" - | ^ ---- reason --- -file not found on filesystem at cwd()/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" - } - } -} - - -2. write file "input/test.importmap" +1. write file "input/test.importmap" { "imports": { "leftpad": "./node_modules/leftpad/index.js" @@ -35,7 +11,7 @@ add mapping to "manualImportmap" } } -3. return +2. return { "test.importmap": { "imports": { From c18408ec46727cc799fcffc58240a2f7208222ff Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 15:36:51 +0200 Subject: [PATCH 10/33] update test --- package.json | 2 +- .../auto_mapping_bare_specifier.test.mjs | 1 - .../output/0_default/0_default_side_effects.txt | 2 +- .../1_bare_specifier_automapping_side_effects.txt | 2 +- .../auto_mapping_css_to_js/auto_mapping_css_to_js.test.mjs | 2 -- .../auto_mapping_css_to_js/output/output_side_effects.txt | 2 +- .../auto_mapping_extensionless_in_node_module.test.mjs | 2 -- .../output/0_default/0_default_side_effects.txt | 2 +- .../1_magic_extensions_js_side_effects.txt | 2 +- .../2_magic_extensions_inherit_side_effects.txt | 2 +- 10 files changed, 7 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4ff9706e..6418d4e6 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@jsenv/package-publish": "1.10.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.2.7", + "@jsenv/snapshot": "2.2.8", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", 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 33177b29..e4f36d6d 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 @@ -21,7 +21,6 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { `./output/${scenario}/`, { filesystemEffects: [`./input/${scenario}.importmap`], - filesystemEffectsInline: true, }, ); }; diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt index 3524ca31..5d417ff9 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt @@ -28,7 +28,7 @@ add mapping to "manualImportmap" "scopes": {} } -3. return +3. resolve { "0_default.importmap": { "imports": {}, diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt index 555b3664..210186fd 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt @@ -6,7 +6,7 @@ "scopes": {} } -2. return +2. resolve { "1_bare_specifier_automapping.importmap": { "imports": { 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 8dfd493a..7cf48e85 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 @@ -20,8 +20,6 @@ const test = async () => { `./output/`, { filesystemEffects: [`./input/test.importmap`], - restoreFilesystem: true, - filesystemEffectsInline: true, }, ); }; diff --git a/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt b/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt index 4e4a67e7..90395266 100644 --- a/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt @@ -6,7 +6,7 @@ "scopes": {} } -2. return +2. resolve { "test.importmap": { "imports": { 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 ded8ea65..b42c9876 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 @@ -20,8 +20,6 @@ const test = async (scenario, { magicExtensions } = {}) => { `./output/${scenario}/`, { filesystemEffects: [`./input/test.importmap`], - restoreFilesystem: true, - filesystemEffectsInline: true, }, ); }; diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt index 22624a2e..0ef82603 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt @@ -30,7 +30,7 @@ add mapping to "manualImportmap" "scopes": {} } -3. return +3. resolve { "test.importmap": { "imports": { diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt index e33c3972..b0968085 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt @@ -21,7 +21,7 @@ file not found on filesystem at cwd()/input/node_modules/leftpad/other-file } } -3. return +3. resolve { "test.importmap": { "imports": { diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt index ce3d8ad8..08475912 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt @@ -11,7 +11,7 @@ } } -2. return +2. resolve { "test.importmap": { "imports": { From 9e282ac586200706d55093b3dab27b03399acecb Mon Sep 17 00:00:00 2001 From: dmail Date: Tue, 23 Jul 2024 21:32:52 +0200 Subject: [PATCH 11/33] small update --- .../auto_mapping_bare_specifier.test.mjs | 8 ++------ .../auto_mapping_css_to_js.test.mjs | 7 ++----- ...to_mapping_extensionless_in_node_module.test.mjs | 7 ++----- tests/snapshot_write_importmaps_side_effects.js | 13 +++++++++++++ 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 tests/snapshot_write_importmaps_side_effects.js 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 e4f36d6d..92a7b1f8 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,9 +1,8 @@ -import { snapshotFunctionSideEffects } 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 test = async (scenario, { bareSpecifierAutomapping }) => { - await snapshotFunctionSideEffects( + await snapshotWriteImportsMapsSideEffects( () => writeImportmaps({ logLevel: "warn", @@ -19,9 +18,6 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { }), import.meta.url, `./output/${scenario}/`, - { - filesystemEffects: [`./input/${scenario}.importmap`], - }, ); }; 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 7cf48e85..46022844 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,8 +1,8 @@ import { writeImportmaps } from "@jsenv/importmap-node-module"; -import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; const test = async () => { - await snapshotFunctionSideEffects( + await snapshotWriteImportsMapsSideEffects( () => writeImportmaps({ logLevel: "warn", @@ -18,9 +18,6 @@ const test = async () => { }), import.meta.url, `./output/`, - { - filesystemEffects: [`./input/test.importmap`], - }, ); }; await test(); 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 b42c9876..e5600ad7 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,8 +1,8 @@ import { writeImportmaps } from "@jsenv/importmap-node-module"; -import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; +import { snapshotWriteImportsMapsSideEffects } from "@jsenv/importmap-node-module/tests/snapshot_write_importmaps_side_effects.js"; const test = async (scenario, { magicExtensions } = {}) => { - await snapshotFunctionSideEffects( + await snapshotWriteImportsMapsSideEffects( () => writeImportmaps({ logLevel: "warn", @@ -18,9 +18,6 @@ const test = async (scenario, { magicExtensions } = {}) => { }), import.meta.url, `./output/${scenario}/`, - { - filesystemEffects: [`./input/test.importmap`], - }, ); }; diff --git a/tests/snapshot_write_importmaps_side_effects.js b/tests/snapshot_write_importmaps_side_effects.js new file mode 100644 index 00000000..07b0e55c --- /dev/null +++ b/tests/snapshot_write_importmaps_side_effects.js @@ -0,0 +1,13 @@ +import { snapshotFunctionSideEffects } from "@jsenv/snapshot"; + +export const snapshotWriteImportsMapsSideEffects = async ( + fn, + fnFileUrl, + sideEffectDirectoryRelativeUrl, +) => { + await snapshotFunctionSideEffects( + fn, + fnFileUrl, + sideEffectDirectoryRelativeUrl, + ); +}; From ac8f3fbd50d5b95c8302b3d470aaf3d7df9e7ce0 Mon Sep 17 00:00:00 2001 From: dmail Date: Wed, 24 Jul 2024 21:29:16 +0200 Subject: [PATCH 12/33] update usage of snapshot --- package.json | 6 +++--- src/util/memoize_async_function.js | 2 +- ...ide_effects.txt => 0_default_side_effects.md} | 16 ++++++++++++---- ...1_bare_specifier_automapping_side_effects.md} | 12 +++++++++--- 4 files changed, 25 insertions(+), 11 deletions(-) rename tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/{0_default_side_effects.txt => 0_default_side_effects.md} (81%) rename tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/{1_bare_specifier_automapping_side_effects.txt => 1_bare_specifier_automapping_side_effects.md} (60%) diff --git a/package.json b/package.json index 6418d4e6..b07e7676 100644 --- a/package.json +++ b/package.json @@ -49,16 +49,16 @@ "@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.5", + "@jsenv/assert": "4.1.6", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.6", + "@jsenv/core": "39.2.7", "@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.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.2.8", + "@jsenv/snapshot": "2.4.1", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", 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/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md similarity index 81% rename from tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt rename to tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md index 5d417ff9..d58090ee 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md @@ -1,4 +1,7 @@ -1. console.warn +1. return promise + +2. console.warn +```console Import resolution failed for "file" --- import trace --- @@ -21,17 +24,22 @@ add mapping to "manualImportmap" } } +``` -2. write file "input/0_default.importmap" +3. write file "input/0_default.importmap" +```importmap { "imports": {}, "scopes": {} } +``` -3. resolve +4. resolve +```js { "0_default.importmap": { "imports": {}, "scopes": {} } -} \ No newline at end of file +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md similarity index 60% rename from tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt rename to tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md index 210186fd..48096139 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md @@ -1,12 +1,17 @@ -1. write file "input/1_bare_specifier_automapping.importmap" +1. return promise + +2. write file "input/1_bare_specifier_automapping.importmap" +```importmap { "imports": { "file": "./file.js" }, "scopes": {} } +``` -2. resolve +3. resolve +```js { "1_bare_specifier_automapping.importmap": { "imports": { @@ -14,4 +19,5 @@ }, "scopes": {} } -} \ No newline at end of file +} +``` \ No newline at end of file From daa0f24a03d88e633871542de89d5c1162348e72 Mon Sep 17 00:00:00 2001 From: dmail Date: Wed, 24 Jul 2024 21:46:33 +0200 Subject: [PATCH 13/33] snapshot on function starts to look wonderful --- package.json | 2 +- .../auto_mapping_bare_specifier.test.mjs | 4 ++-- ...de_effects.md => 0_bare_specifier_warning.md} | 4 ++-- ...ffects.md => 1_bare_specifier_automapping.md} | 0 .../auto_mapping_css_to_js.test.mjs | 2 +- ...ide_effects.txt => auto_mapping_css_to_js.md} | 12 +++++++++--- ...mapping_extensionless_in_node_module.test.mjs | 4 ++-- ...effects.txt => 0_magic_extensions_warning.md} | 16 ++++++++++++---- ...side_effects.txt => 1_magic_extensions_js.md} | 16 ++++++++++++---- ...effects.txt => 2_magic_extensions_inherit.md} | 12 +++++++++--- tests/snapshot_write_importmaps_side_effects.js | 2 ++ 11 files changed, 52 insertions(+), 22 deletions(-) rename tests/entry_point_check/auto_mapping_bare_specifier/output/{0_default/0_default_side_effects.md => 0_bare_specifier_warning.md} (86%) rename tests/entry_point_check/auto_mapping_bare_specifier/output/{1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md => 1_bare_specifier_automapping.md} (100%) rename tests/entry_point_check/auto_mapping_css_to_js/output/{output_side_effects.txt => auto_mapping_css_to_js.md} (65%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/{0_default/0_default_side_effects.txt => 0_magic_extensions_warning.md} (85%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/{1_magic_extensions_js/1_magic_extensions_js_side_effects.txt => 1_magic_extensions_js.md} (84%) rename tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/{2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt => 2_magic_extensions_inherit.md} (86%) diff --git a/package.json b/package.json index b07e7676..ae7c7e33 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@jsenv/package-publish": "1.10.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.4.1", + "@jsenv/snapshot": "2.5.0", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", 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 92a7b1f8..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 @@ -17,11 +17,11 @@ const test = async (scenario, { bareSpecifierAutomapping }) => { }, }), import.meta.url, - `./output/${scenario}/`, + `./output/${scenario}.md`, ); }; -await test("0_default", { +await test("0_bare_specifier_warning", { bareSpecifierAutomapping: undefined, }); await test("1_bare_specifier_automapping", { diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md similarity index 86% rename from tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md rename to tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md index d58090ee..45aaef46 100644 --- a/tests/entry_point_check/auto_mapping_bare_specifier/output/0_default/0_default_side_effects.md +++ b/tests/entry_point_check/auto_mapping_bare_specifier/output/0_bare_specifier_warning.md @@ -26,7 +26,7 @@ add mapping to "manualImportmap" ``` -3. write file "input/0_default.importmap" +3. write file "input/0_bare_specifier_warning.importmap" ```importmap { "imports": {}, @@ -37,7 +37,7 @@ add mapping to "manualImportmap" 4. resolve ```js { - "0_default.importmap": { + "0_bare_specifier_warning.importmap": { "imports": {}, "scopes": {} } diff --git a/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md b/tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping.md similarity index 100% rename from tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping/1_bare_specifier_automapping_side_effects.md rename to tests/entry_point_check/auto_mapping_bare_specifier/output/1_bare_specifier_automapping.md 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 46022844..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 @@ -17,7 +17,7 @@ const test = async () => { }, }), import.meta.url, - `./output/`, + `./output/auto_mapping_css_to_js.md`, ); }; await test(); diff --git a/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt b/tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md similarity index 65% rename from tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt rename to tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md index 90395266..6a27c8c1 100644 --- a/tests/entry_point_check/auto_mapping_css_to_js/output/output_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_css_to_js/output/auto_mapping_css_to_js.md @@ -1,12 +1,17 @@ -1. write file "input/test.importmap" +1. return promise + +2. write file "input/test.importmap" +```importmap { "imports": { "./file.css": "./file.css.js" }, "scopes": {} } +``` -2. resolve +3. resolve +```js { "test.importmap": { "imports": { @@ -14,4 +19,5 @@ }, "scopes": {} } -} \ No newline at end of file +} +``` \ 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 e5600ad7..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 @@ -17,11 +17,11 @@ const test = async (scenario, { magicExtensions } = {}) => { }, }), import.meta.url, - `./output/${scenario}/`, + `./output/${scenario}.md`, ); }; -await test("0_default", { +await test("0_magic_extensions_warning", { magicExtensions: undefined, }); await test("1_magic_extensions_js", { diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md similarity index 85% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md index 0ef82603..3a955496 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_default/0_default_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/0_magic_extensions_warning.md @@ -1,4 +1,7 @@ -1. console.warn +1. return promise + +2. console.warn +```console Import resolution failed for "./file" --- import trace --- @@ -21,16 +24,20 @@ add mapping to "manualImportmap" } } +``` -2. write file "input/test.importmap" +3. write file "input/test.importmap" +```importmap { "imports": { "leftpad": "./node_modules/leftpad/index.js" }, "scopes": {} } +``` -3. resolve +4. resolve +```js { "test.importmap": { "imports": { @@ -38,4 +45,5 @@ add mapping to "manualImportmap" }, "scopes": {} } -} \ No newline at end of file +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md similarity index 84% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md index b0968085..7dd8500f 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js/1_magic_extensions_js_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/1_magic_extensions_js.md @@ -1,4 +1,7 @@ -1. console.warn +1. return promise + +2. console.warn +```console Import resolution failed for "./other-file" --- import trace --- @@ -8,8 +11,10 @@ file:///cwd()/input/node_modules/leftpad/file.js:1:7 --- reason --- file not found on filesystem at cwd()/input/node_modules/leftpad/other-file +``` -2. write file "input/test.importmap" +3. write file "input/test.importmap" +```importmap { "imports": { "leftpad": "./node_modules/leftpad/index.js" @@ -20,8 +25,10 @@ file not found on filesystem at cwd()/input/node_modules/leftpad/other-file } } } +``` -3. resolve +4. resolve +```js { "test.importmap": { "imports": { @@ -33,4 +40,5 @@ file not found on filesystem at cwd()/input/node_modules/leftpad/other-file } } } -} \ No newline at end of file +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md similarity index 86% rename from tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt rename to tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md index 08475912..6fca02de 100644 --- a/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit/2_magic_extensions_inherit_side_effects.txt +++ b/tests/entry_point_check/auto_mapping_extensionless_in_node_module/output/2_magic_extensions_inherit.md @@ -1,4 +1,7 @@ -1. write file "input/test.importmap" +1. return promise + +2. write file "input/test.importmap" +```importmap { "imports": { "leftpad": "./node_modules/leftpad/index.js" @@ -10,8 +13,10 @@ } } } +``` -2. resolve +3. resolve +```js { "test.importmap": { "imports": { @@ -24,4 +29,5 @@ } } } -} \ No newline at end of file +} +``` \ No newline at end of file diff --git a/tests/snapshot_write_importmaps_side_effects.js b/tests/snapshot_write_importmaps_side_effects.js index 07b0e55c..99898ff9 100644 --- a/tests/snapshot_write_importmaps_side_effects.js +++ b/tests/snapshot_write_importmaps_side_effects.js @@ -4,10 +4,12 @@ export const snapshotWriteImportsMapsSideEffects = async ( fn, fnFileUrl, sideEffectDirectoryRelativeUrl, + options, ) => { await snapshotFunctionSideEffects( fn, fnFileUrl, sideEffectDirectoryRelativeUrl, + options, ); }; From c43369cacabec4939129cb71c7ee26f59c09c24c Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 10:01:38 +0200 Subject: [PATCH 14/33] update dep --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae7c7e33..d5dbad2b 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@jsenv/package-publish": "1.10.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.5.0", + "@jsenv/snapshot": "2.5.1", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", From ab5b07e6600291747197134d0f2864c14e0330d3 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 10:09:04 +0200 Subject: [PATCH 15/33] update dep --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5dbad2b..3d82d268 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@jsenv/package-publish": "1.10.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.5.1", + "@jsenv/snapshot": "2.5.2", "@jsenv/test": "3.3.17", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", From 93d32b79eb71237f9a78877269923c112d3b80c7 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 10:11:21 +0200 Subject: [PATCH 16/33] update node version --- .github/workflows/main.yml | 4 ++-- .github/workflows/performance_impact.yml | 2 +- package.json | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) 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/package.json b/package.json index 3d82d268..4e50b849 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "workspaces": [ "./docs/demo" ], + "volta": { + "node": "22.3.0" + }, "scripts": { "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html", "test": "node ./scripts/test.mjs", From f41d783a536479150ce5624d678ac8da653cb1f4 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 10:19:52 +0200 Subject: [PATCH 17/33] update deps --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4e50b849..2d4ac0cb 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", "@jsenv/ast": "6.2.6", - "@jsenv/filesystem": "4.9.2", + "@jsenv/filesystem": "4.9.3", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", "@jsenv/urls": "2.3.2" @@ -54,15 +54,15 @@ "@babel/plugin-syntax-jsx": "7.24.7", "@jsenv/assert": "4.1.6", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.7", + "@jsenv/core": "39.2.8", "@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.5", "@jsenv/performance-impact": "4.2.1", - "@jsenv/server": "15.2.14", - "@jsenv/snapshot": "2.5.2", - "@jsenv/test": "3.3.17", + "@jsenv/server": "15.2.15", + "@jsenv/snapshot": "2.5.3", + "@jsenv/test": "3.3.18", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", From 1c061210dd018c264e4ecee0c1b199c450820486 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 11:02:24 +0200 Subject: [PATCH 18/33] update test --- .../auto_mapping_lodash.test.mjs | 79 +++++-------------- .../{root => input}/main.js | 0 .../node_modules/lodash/package.json | 0 .../node_modules/lodash/union.js | 0 .../{root => input}/package.json | 0 .../output/0_magic_extensions_ts.md | 38 +++++++++ .../output/1_magic_extensions_js.md | 25 ++++++ .../root/magic_extensions_js.importmap | 7 -- .../root/magic_extensions_ts.importmap | 6 -- 9 files changed, 82 insertions(+), 73 deletions(-) rename tests/entry_point_check/auto_mapping_lodash/{root => input}/main.js (100%) rename tests/entry_point_check/auto_mapping_lodash/{root => input}/node_modules/lodash/package.json (100%) rename tests/entry_point_check/auto_mapping_lodash/{root => input}/node_modules/lodash/union.js (100%) rename tests/entry_point_check/auto_mapping_lodash/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/auto_mapping_lodash/output/0_magic_extensions_ts.md create mode 100644 tests/entry_point_check/auto_mapping_lodash/output/1_magic_extensions_js.md delete mode 100644 tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_js.importmap delete mode 100644 tests/entry_point_check/auto_mapping_lodash/root/magic_extensions_ts.importmap 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 257c32a4..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 { assert } from "@jsenv/assert"; -import { takeFileSnapshot } from "@jsenv/snapshot"; -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, - expect: 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..f6e8243b --- /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:///cwd()/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 cwd()/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 From 043091ad8993e3b89ba46cba4cfd5a9244a5d039 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 11:07:09 +0200 Subject: [PATCH 19/33] update an other test --- .gitignore | 2 + .../entry_point_file_not_found.test.mjs | 70 +++++++------------ .../0_not_found}/package.json | 0 .../{root => fixtures/1_found}/main.js | 0 .../fixtures/1_found/package.json | 9 +++ .../output/0_not_found.md | 30 ++++++++ .../output/1_found.md | 19 +++++ .../root/test.importmap | 4 -- 8 files changed, 84 insertions(+), 50 deletions(-) rename tests/entry_point_check/entry_point_file_not_found/{root => fixtures/0_not_found}/package.json (100%) rename tests/entry_point_check/entry_point_file_not_found/{root => fixtures/1_found}/main.js (100%) create mode 100644 tests/entry_point_check/entry_point_file_not_found/fixtures/1_found/package.json create mode 100644 tests/entry_point_check/entry_point_file_not_found/output/0_not_found.md create mode 100644 tests/entry_point_check/entry_point_file_not_found/output/1_found.md delete mode 100644 tests/entry_point_check/entry_point_file_not_found/root/test.importmap diff --git a/.gitignore b/.gitignore index 5ec64764..dcaf1195 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ .DS_Store +**/git_ignored/ + 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 6a91e41c..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 { removeFileSync, writeFileSync } 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 expect = [ - { - 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, expect }); -} - -writeFileSync(mainJsFileUrl); -{ - const actual = await getWarnings(); - const expect = []; - assert({ actual, expect }); -} +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..7fc0ed5e --- /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 cwd()/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 From 7f696c8a89d7435c97ce3b6b571c849315fda3c4 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 12:17:40 +0200 Subject: [PATCH 20/33] update snapshots --- package.json | 12 ++++++------ .../output/0_bare_specifier_warning.md | 2 +- .../output/0_magic_extensions_warning.md | 4 ++-- .../output/1_magic_extensions_js.md | 4 ++-- .../output/0_magic_extensions_ts.md | 4 ++-- .../entry_point_file_not_found/output/0_not_found.md | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 2d4ac0cb..41342167 100644 --- a/package.json +++ b/package.json @@ -40,11 +40,11 @@ "dependencies": { "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", - "@jsenv/ast": "6.2.6", - "@jsenv/filesystem": "4.9.3", + "@jsenv/ast": "6.2.7", + "@jsenv/filesystem": "4.9.4", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", - "@jsenv/urls": "2.3.2" + "@jsenv/urls": "2.4.0" }, "devDependencies": { "@babel/eslint-parser": "7.24.8", @@ -54,15 +54,15 @@ "@babel/plugin-syntax-jsx": "7.24.7", "@jsenv/assert": "4.1.6", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.8", + "@jsenv/core": "39.2.9", "@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.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.15", - "@jsenv/snapshot": "2.5.3", - "@jsenv/test": "3.3.18", + "@jsenv/snapshot": "2.6.0", + "@jsenv/test": "3.3.19", "eslint": "8.57.0", "eslint-plugin-html": "8.1.1", "eslint-plugin-import": "2.29.1", 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 index 45aaef46..34bf33a9 100644 --- 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 @@ -5,7 +5,7 @@ Import resolution failed for "file" --- import trace --- -file:///cwd()/input/index.js:2:7 +file:////input/index.js:2:7 1 | // eslint-disable-next-line import/no-unresolved > 2 | import "file"; | ^ 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 index 3a955496..b092b7ca 100644 --- 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 @@ -5,11 +5,11 @@ Import resolution failed for "./file" --- import trace --- -file:///cwd()/input/node_modules/leftpad/index.js:1:7 +file:////input/node_modules/leftpad/index.js:1:7 > 1 | import "./file" | ^ --- reason --- -file not found on filesystem at cwd()/input/node_modules/leftpad/file +file not found on filesystem at /input/node_modules/leftpad/file --- suggestion 1 --- update import specifier to "./file.js" --- suggestion 2 --- 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 index 7dd8500f..79fdfe98 100644 --- 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 @@ -5,11 +5,11 @@ Import resolution failed for "./other-file" --- import trace --- -file:///cwd()/input/node_modules/leftpad/file.js:1:7 +file:////input/node_modules/leftpad/file.js:1:7 > 1 | import "./other-file" | ^ --- reason --- -file not found on filesystem at cwd()/input/node_modules/leftpad/other-file +file not found on filesystem at /input/node_modules/leftpad/other-file ``` 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 index f6e8243b..a53ff40d 100644 --- 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 @@ -5,13 +5,13 @@ Import resolution failed for "lodash/union" --- import trace --- -file:///cwd()/input/main.js:2:22 +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 cwd()/input/node_modules/lodash/union +file not found on filesystem at /input/node_modules/lodash/union ``` 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 index 7fc0ed5e..e2641c75 100644 --- 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 @@ -7,7 +7,7 @@ Import resolution failed for "./main.js" --- import trace --- entryPoints parameter --- reason --- -file not found on filesystem at cwd()/git_ignored/main.js +file not found on filesystem at /git_ignored/main.js ``` From 995a92ec017830747fe839562aeb10918f2c6104 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 12:19:46 +0200 Subject: [PATCH 21/33] migrate an other test --- .../entry_point_html_script_module.test.mjs | 50 +++++++++---------- .../{root => input}/a.js | 0 .../{root => input}/b.js | 0 .../{root => input}/c.js | 0 .../{root => input}/everything.js | 0 .../{root => input}/main.html | 0 .../{root => input}/package.json | 0 .../output/entry_point_html_script_module.md | 31 ++++++++++++ .../root/test.importmap | 10 ---- 9 files changed, 56 insertions(+), 35 deletions(-) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/a.js (100%) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/b.js (100%) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/c.js (100%) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/everything.js (100%) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/main.html (100%) rename tests/entry_point_check/entry_point_html_script_module/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/entry_point_html_script_module/output/entry_point_html_script_module.md delete mode 100644 tests/entry_point_check/entry_point_html_script_module/root/test.importmap 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 From 6e7b54de7ac6c5d9d7704735a2419c481a9c4bbf Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:38:10 +0200 Subject: [PATCH 22/33] migrate some test --- .../entry_point_many.test.mjs | 40 +++++------ .../{root => input}/common.js | 0 .../{root => input}/first/first.js | 0 .../{root => input}/package.json | 0 .../{root => input}/second/second.js | 0 .../output/entry_point_html_script_module.md | 23 ++++++ .../entry_point_many/root/test.importmap | 6 -- .../entry_point_many_2.test.mjs | 60 +++++----------- .../{root => fixtures}/about.js | 0 .../{root => fixtures}/index.js | 0 .../{root => fixtures}/node_modules/foo/a.js | 0 .../{root => fixtures}/node_modules/foo/b.js | 0 .../node_modules/foo/foo.js | 0 .../node_modules/foo/package.json | 0 .../{root => fixtures}/package.json | 0 .../output/entry_point_many_2.md | 71 +++++++++++++++++++ .../entry_point_many_2/root/about.html | 18 ----- .../entry_point_many_2/root/index.html | 12 ---- .../entry_point_many_2/snapshots/about.html | 21 ------ .../entry_point_many_2/snapshots/index.html | 21 ------ 20 files changed, 133 insertions(+), 139 deletions(-) rename tests/entry_point_check/entry_point_many/{root => input}/common.js (100%) rename tests/entry_point_check/entry_point_many/{root => input}/first/first.js (100%) rename tests/entry_point_check/entry_point_many/{root => input}/package.json (100%) rename tests/entry_point_check/entry_point_many/{root => input}/second/second.js (100%) create mode 100644 tests/entry_point_check/entry_point_many/output/entry_point_html_script_module.md delete mode 100644 tests/entry_point_check/entry_point_many/root/test.importmap rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/about.js (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/index.js (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/node_modules/foo/a.js (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/node_modules/foo/b.js (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/node_modules/foo/foo.js (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/node_modules/foo/package.json (100%) rename tests/entry_point_check/entry_point_many_2/{root => fixtures}/package.json (100%) create mode 100644 tests/entry_point_check/entry_point_many_2/output/entry_point_many_2.md delete mode 100644 tests/entry_point_check/entry_point_many_2/root/about.html delete mode 100644 tests/entry_point_check/entry_point_many_2/root/index.html delete mode 100644 tests/entry_point_check/entry_point_many_2/snapshots/about.html delete mode 100644 tests/entry_point_check/entry_point_many_2/snapshots/index.html 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 a6d87d85..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 { copyFileSync } from "@jsenv/filesystem"; -import { takeDirectorySnapshot } from "@jsenv/snapshot"; - +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 From facc2cb1cb56f5e11fb5c358eb0b97bc42cfef92 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:40:26 +0200 Subject: [PATCH 23/33] update some test --- .../extensionless_and_exports.test.mjs | 34 +++++++++---------- .../{root => input}/index.js | 0 .../{root => input}/node_modules/foo/file.js | 0 .../{root => input}/node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 0 .../{root => input}/package.json | 0 .../output/extensionless_and_exports.md | 23 +++++++++++++ .../root/test.importmap | 6 ---- .../js_import_circular/{root => input}/a.js | 0 .../{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../js_import_circular.test.mjs | 32 ++++++++--------- .../output/js_import_circular.md | 19 +++++++++++ .../js_import_circular/root/test.importmap | 4 --- 14 files changed, 75 insertions(+), 43 deletions(-) rename tests/entry_point_check/extensionless_and_exports/{root => input}/index.js (100%) rename tests/entry_point_check/extensionless_and_exports/{root => input}/node_modules/foo/file.js (100%) rename tests/entry_point_check/extensionless_and_exports/{root => input}/node_modules/foo/index.js (100%) rename tests/entry_point_check/extensionless_and_exports/{root => input}/node_modules/foo/package.json (100%) rename tests/entry_point_check/extensionless_and_exports/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/extensionless_and_exports/output/extensionless_and_exports.md delete mode 100644 tests/entry_point_check/extensionless_and_exports/root/test.importmap rename tests/entry_point_check/js_import_circular/{root => input}/a.js (100%) rename tests/entry_point_check/js_import_circular/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_circular/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_circular/output/js_import_circular.md delete mode 100644 tests/entry_point_check/js_import_circular/root/test.importmap 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 From 7dacbadca0df80f0cfb6108478f3e5aa1c75bd80 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:43:49 +0200 Subject: [PATCH 24/33] migrate more test --- .../{root => input}/a.js | 0 .../{root => input}/b.js | 0 .../{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../js_import_circular_deep.test.mjs | 31 +++++---- .../output/js_import_circular_deep.md | 19 +++++ .../root/test.importmap | 4 -- .../js_import_fs/{root => input}/index.js | 0 .../js_import_fs/{root => input}/package.json | 0 .../js_import_fs/js_import_fs.test.mjs | 69 ++++++------------- .../js_import_fs/output/0_runtime_browser.md | 35 ++++++++++ .../js_import_fs/output/1_runtime_node.md | 19 +++++ .../root/runtime_browser.importmap | 4 -- .../js_import_fs/root/runtime_node.importmap | 4 -- .../js_import_http/{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../js_import_http/js_import_http.test.mjs | 40 +++++------ .../js_import_http/output/js_import_http.md | 23 +++++++ .../js_import_http/root/test.importmap | 6 -- 19 files changed, 153 insertions(+), 101 deletions(-) rename tests/entry_point_check/js_import_circular_deep/{root => input}/a.js (100%) rename tests/entry_point_check/js_import_circular_deep/{root => input}/b.js (100%) rename tests/entry_point_check/js_import_circular_deep/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_circular_deep/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_circular_deep/output/js_import_circular_deep.md delete mode 100644 tests/entry_point_check/js_import_circular_deep/root/test.importmap rename tests/entry_point_check/js_import_fs/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_fs/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_fs/output/0_runtime_browser.md create mode 100644 tests/entry_point_check/js_import_fs/output/1_runtime_node.md delete mode 100644 tests/entry_point_check/js_import_fs/root/runtime_browser.importmap delete mode 100644 tests/entry_point_check/js_import_fs/root/runtime_node.importmap rename tests/entry_point_check/js_import_http/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_http/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_http/output/js_import_http.md delete mode 100644 tests/entry_point_check/js_import_http/root/test.importmap 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 718f0650..2cbe48f1 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 { assert } from "@jsenv/assert"; -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 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 expect = expectedWarnings; - assert({ actual, expect }); + }), + 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_runtime_browser", { + runtime: undefined, }); - -await test({ - name: "runtime_node", +await test("1_runtime_node", { runtime: "node", - expectedWarnings: [], }); diff --git a/tests/entry_point_check/js_import_fs/output/0_runtime_browser.md b/tests/entry_point_check/js_import_fs/output/0_runtime_browser.md new file mode 100644 index 00000000..2a38912e --- /dev/null +++ b/tests/entry_point_check/js_import_fs/output/0_runtime_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_runtime_browser.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +4. resolve +```js +{ + "0_runtime_browser.importmap": { + "imports": {}, + "scopes": {} + } +} +``` \ No newline at end of file diff --git a/tests/entry_point_check/js_import_fs/output/1_runtime_node.md b/tests/entry_point_check/js_import_fs/output/1_runtime_node.md new file mode 100644 index 00000000..af5e9d80 --- /dev/null +++ b/tests/entry_point_check/js_import_fs/output/1_runtime_node.md @@ -0,0 +1,19 @@ +1. return promise + +2. write file "input/1_runtime_node.importmap" +```importmap +{ + "imports": {}, + "scopes": {} +} +``` + +3. resolve +```js +{ + "1_runtime_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 From 6520a39fb199e266575d3582189da3eb4c2e5d4b Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:46:11 +0200 Subject: [PATCH 25/33] update tests --- .../js_import_fs/js_import_fs.test.mjs | 6 +- ...time_browser.md => 0_import_fs_browser.md} | 4 +- ...{1_runtime_node.md => 1_import_fs_node.md} | 4 +- .../{root => input}/foo.js | 0 .../{root => input}/main.js | 0 .../{root => input}/package.json | 0 .../js_import_leading_slash.test.mjs | 69 ++++++------------- .../output/0_leading_slash_browser.md | 19 +++++ .../output/1_leading_slash_node.md | 34 +++++++++ .../root/runtime_browser.importmap | 4 -- .../root/runtime_node.importmap | 4 -- 11 files changed, 80 insertions(+), 64 deletions(-) rename tests/entry_point_check/js_import_fs/output/{0_runtime_browser.md => 0_import_fs_browser.md} (81%) rename tests/entry_point_check/js_import_fs/output/{1_runtime_node.md => 1_import_fs_node.md} (62%) rename tests/entry_point_check/js_import_leading_slash/{root => input}/foo.js (100%) rename tests/entry_point_check/js_import_leading_slash/{root => input}/main.js (100%) rename tests/entry_point_check/js_import_leading_slash/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_leading_slash/output/0_leading_slash_browser.md create mode 100644 tests/entry_point_check/js_import_leading_slash/output/1_leading_slash_node.md delete mode 100644 tests/entry_point_check/js_import_leading_slash/root/runtime_browser.importmap delete mode 100644 tests/entry_point_check/js_import_leading_slash/root/runtime_node.importmap 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 2cbe48f1..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 @@ -21,9 +21,9 @@ const test = async (scenario, { runtime }) => { ); }; -await test("0_runtime_browser", { - runtime: undefined, +await test("0_import_fs_browser", { + runtime: "browser", }); -await test("1_runtime_node", { +await test("1_import_fs_node", { runtime: "node", }); diff --git a/tests/entry_point_check/js_import_fs/output/0_runtime_browser.md b/tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md similarity index 81% rename from tests/entry_point_check/js_import_fs/output/0_runtime_browser.md rename to tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md index 2a38912e..464f17d5 100644 --- a/tests/entry_point_check/js_import_fs/output/0_runtime_browser.md +++ b/tests/entry_point_check/js_import_fs/output/0_import_fs_browser.md @@ -16,7 +16,7 @@ use runtime: "node" ``` -3. write file "input/0_runtime_browser.importmap" +3. write file "input/0_import_fs_browser.importmap" ```importmap { "imports": {}, @@ -27,7 +27,7 @@ use runtime: "node" 4. resolve ```js { - "0_runtime_browser.importmap": { + "0_import_fs_browser.importmap": { "imports": {}, "scopes": {} } diff --git a/tests/entry_point_check/js_import_fs/output/1_runtime_node.md b/tests/entry_point_check/js_import_fs/output/1_import_fs_node.md similarity index 62% rename from tests/entry_point_check/js_import_fs/output/1_runtime_node.md rename to tests/entry_point_check/js_import_fs/output/1_import_fs_node.md index af5e9d80..a4dbc1ec 100644 --- a/tests/entry_point_check/js_import_fs/output/1_runtime_node.md +++ b/tests/entry_point_check/js_import_fs/output/1_import_fs_node.md @@ -1,6 +1,6 @@ 1. return promise -2. write file "input/1_runtime_node.importmap" +2. write file "input/1_import_fs_node.importmap" ```importmap { "imports": {}, @@ -11,7 +11,7 @@ 3. resolve ```js { - "1_runtime_node.importmap": { + "1_import_fs_node.importmap": { "imports": {}, "scopes": {} } 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 0c8bdf69..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 { assert } from "@jsenv/assert"; -import { takeFileSnapshot } from "@jsenv/snapshot"; -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 expect = - 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, expect }); + }, + }), + 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 From d65ec2f54a625a3f7c2c21aef4d6857181265f35 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:48:57 +0200 Subject: [PATCH 26/33] more test updates --- .../{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../js_import_node_scheme.test.mjs | 34 +++++++++---------- .../output/js_import_node_scheme.md | 19 +++++++++++ .../js_import_node_scheme/root/test.importmap | 4 --- .../{root => input}/index.js | 0 .../{root => input}/node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 0 .../{root => input}/package.json | 0 ...ferencing_dependency_package_name.test.mjs | 34 +++++++++---------- ...ort_referencing_dependency_package_name.md | 29 ++++++++++++++++ .../root/test.importmap | 9 ----- .../{root => input}/index.js | 0 .../{root => input}/lib/boo.js | 0 .../{root => input}/node_modules/foo/index | 0 .../node_modules/foo/package.json | 0 .../node_modules/foo/src/bar.js | 0 .../{root => input}/package.json | 0 ...ort_referencing_many_package_name.test.mjs | 34 +++++++++---------- ...js_import_referencing_many_package_name.md | 33 ++++++++++++++++++ .../root/test.importmap | 11 ------ 21 files changed, 132 insertions(+), 75 deletions(-) rename tests/entry_point_check/js_import_node_scheme/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_node_scheme/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_node_scheme/output/js_import_node_scheme.md delete mode 100644 tests/entry_point_check/js_import_node_scheme/root/test.importmap rename tests/entry_point_check/js_import_referencing_dependency_package_name/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_referencing_dependency_package_name/{root => input}/node_modules/foo/index.js (100%) rename tests/entry_point_check/js_import_referencing_dependency_package_name/{root => input}/node_modules/foo/package.json (100%) rename tests/entry_point_check/js_import_referencing_dependency_package_name/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_dependency_package_name/output/js_import_referencing_dependency_package_name.md delete mode 100644 tests/entry_point_check/js_import_referencing_dependency_package_name/root/test.importmap rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/lib/boo.js (100%) rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/node_modules/foo/index (100%) rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/node_modules/foo/package.json (100%) rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/node_modules/foo/src/bar.js (100%) rename tests/entry_point_check/js_import_referencing_many_package_name/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_many_package_name/output/js_import_referencing_many_package_name.md delete mode 100644 tests/entry_point_check/js_import_referencing_many_package_name/root/test.importmap 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 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 From fc109a5741e121504dd3f958ae6086e793ca705a Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:50:43 +0200 Subject: [PATCH 27/33] more test --- .../{root => input}/file.js | 0 .../{root => input}/index.js | 0 .../{root => input}/package.json | 0 ...ort_referencing_root_package_name.test.mjs | 34 ++++++++-------- ...js_import_referencing_root_package_name.md | 25 ++++++++++++ .../root/test.importmap | 7 ---- .../{root => input}/index.js | 0 .../node_modules/@jsenv/core/package.json | 0 .../{root => input}/package.json | 0 ..._referencing_subpath_all_exported.test.mjs | 40 +++++++++---------- ...import_referencing_subpath_all_exported.md | 33 +++++++++++++++ .../root/test.importmap | 11 ----- .../{root => input}/index | 0 .../node_modules/@jsenv/core/index | 0 .../node_modules/@jsenv/core/package.json | 0 .../{root => input}/package.json | 0 ...eferencing_subpath_all_exported_2.test.mjs | 40 +++++++++---------- ...port_referencing_subpath_all_exported_2.md | 35 ++++++++++++++++ .../root/test.importmap | 12 ------ 19 files changed, 150 insertions(+), 87 deletions(-) rename tests/entry_point_check/js_import_referencing_root_package_name/{root => input}/file.js (100%) rename tests/entry_point_check/js_import_referencing_root_package_name/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_referencing_root_package_name/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_root_package_name/output/js_import_referencing_root_package_name.md delete mode 100644 tests/entry_point_check/js_import_referencing_root_package_name/root/test.importmap rename tests/entry_point_check/js_import_referencing_subpath_all_exported/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_referencing_subpath_all_exported/{root => input}/node_modules/@jsenv/core/package.json (100%) rename tests/entry_point_check/js_import_referencing_subpath_all_exported/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_subpath_all_exported/output/js_import_referencing_subpath_all_exported.md delete mode 100644 tests/entry_point_check/js_import_referencing_subpath_all_exported/root/test.importmap rename tests/entry_point_check/js_import_referencing_subpath_all_exported_2/{root => input}/index (100%) rename tests/entry_point_check/js_import_referencing_subpath_all_exported_2/{root => input}/node_modules/@jsenv/core/index (100%) rename tests/entry_point_check/js_import_referencing_subpath_all_exported_2/{root => input}/node_modules/@jsenv/core/package.json (100%) rename tests/entry_point_check/js_import_referencing_subpath_all_exported_2/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_subpath_all_exported_2/output/js_import_referencing_subpath_all_exported_2.md delete mode 100644 tests/entry_point_check/js_import_referencing_subpath_all_exported_2/root/test.importmap 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 From 741b3a27e74a7b12d5e19191bf867a2b3b83c344 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 13:52:53 +0200 Subject: [PATCH 28/33] all entry point test migrated --- .../{root => input}/index.js | 0 .../node_modules/@jsenv/core/package.json | 0 .../{root => input}/package.json | 0 ...port_referencing_subpath_exported.test.mjs | 32 +++++++-------- .../js_import_referencing_subpath_exported.md | 39 +++++++++++++++++++ .../root/test.importmap | 14 ------- .../{root => input}/.eslintrc.cjs | 0 .../{root => input}/babel.config.cjs | 0 .../{root => input}/index.js | 0 .../{root => input}/package.json | 0 .../js_using_decorators.test.mjs | 32 +++++++-------- .../output/js_using_decorators.md | 19 +++++++++ .../js_using_decorators/root/test.importmap | 4 -- .../{root => input}/file.js | 0 .../{root => input}/index.js | 0 .../js_using_import_assertions.test.mjs | 36 ++++++++--------- .../output/js_using_import_assertions.md | 23 +++++++++++ .../root/test.importmap | 6 --- 18 files changed, 131 insertions(+), 74 deletions(-) rename tests/entry_point_check/js_import_referencing_subpath_exported/{root => input}/index.js (100%) rename tests/entry_point_check/js_import_referencing_subpath_exported/{root => input}/node_modules/@jsenv/core/package.json (100%) rename tests/entry_point_check/js_import_referencing_subpath_exported/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_import_referencing_subpath_exported/output/js_import_referencing_subpath_exported.md delete mode 100644 tests/entry_point_check/js_import_referencing_subpath_exported/root/test.importmap rename tests/entry_point_check/js_using_decorators/{root => input}/.eslintrc.cjs (100%) rename tests/entry_point_check/js_using_decorators/{root => input}/babel.config.cjs (100%) rename tests/entry_point_check/js_using_decorators/{root => input}/index.js (100%) rename tests/entry_point_check/js_using_decorators/{root => input}/package.json (100%) create mode 100644 tests/entry_point_check/js_using_decorators/output/js_using_decorators.md delete mode 100644 tests/entry_point_check/js_using_decorators/root/test.importmap rename tests/entry_point_check/js_using_import_assertions/{root => input}/file.js (100%) rename tests/entry_point_check/js_using_import_assertions/{root => input}/index.js (100%) create mode 100644 tests/entry_point_check/js_using_import_assertions/output/js_using_import_assertions.md delete mode 100644 tests/entry_point_check/js_using_import_assertions/root/test.importmap 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 From 502e64cf6e3168188ee4165abff14e940fc29e26 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 14:03:17 +0200 Subject: [PATCH 29/33] more test migrated --- .gitignore | 1 + .../manual_importmap/env_dev/env_dev.test.mjs | 40 +++++++++--------- .../env_dev/{root => input}/env.dev.js | 0 .../env_dev/{root => input}/index.js | 0 .../env_dev/{root => input}/package.json | 0 .../env_dev/output/env_dev.md | 23 +++++++++++ .../env_dev/root/test.importmap | 6 --- .../file_override/file_override.test.mjs | 37 +++++++++-------- .../file_override/{root => input}/index.mjs | 0 .../node_modules/foo/button.css.js | 0 .../node_modules/foo/button.js | 0 .../node_modules/foo/package.json | 0 .../{root => input}/package.json | 0 .../file_override/output/file_override.md | 31 ++++++++++++++ .../file_override/root/test.importmap | 10 ----- .../file_override_scope.test.mjs | 41 ++++++++++--------- .../{root => input}/index.mjs | 0 .../node_modules/bar/button.css.js | 0 .../node_modules/bar/package.json | 0 .../node_modules/foo/index.mjs | 0 .../node_modules/foo/package.json | 0 .../{root => input}/package.json | 0 .../output/file_override_scope.md | 31 ++++++++++++++ .../file_override_scope/root/test.importmap | 10 ----- .../preact_override/{root => input}/index.js | 0 .../node_modules/preact/compat/index.js | 0 .../node_modules/preact/index.js | 0 .../node_modules/preact/package.json | 0 .../node_modules/react-redux/index.js | 0 .../node_modules/react-redux/package.json | 0 .../node_modules/react/index.js | 0 .../node_modules/react/package.json | 0 .../{root => input}/package.json | 0 .../preact_override/output/preact_override.md | 41 +++++++++++++++++++ .../preact_override/preact_override.test.mjs | 37 +++++++++-------- .../preact_override/root/test.importmap | 15 ------- 36 files changed, 206 insertions(+), 117 deletions(-) rename tests/manual_importmap/env_dev/{root => input}/env.dev.js (100%) rename tests/manual_importmap/env_dev/{root => input}/index.js (100%) rename tests/manual_importmap/env_dev/{root => input}/package.json (100%) create mode 100644 tests/manual_importmap/env_dev/output/env_dev.md delete mode 100644 tests/manual_importmap/env_dev/root/test.importmap rename tests/manual_importmap/file_override/{root => input}/index.mjs (100%) rename tests/manual_importmap/file_override/{root => input}/node_modules/foo/button.css.js (100%) rename tests/manual_importmap/file_override/{root => input}/node_modules/foo/button.js (100%) rename tests/manual_importmap/file_override/{root => input}/node_modules/foo/package.json (100%) rename tests/manual_importmap/file_override/{root => input}/package.json (100%) create mode 100644 tests/manual_importmap/file_override/output/file_override.md delete mode 100644 tests/manual_importmap/file_override/root/test.importmap rename tests/manual_importmap/file_override_scope/{root => input}/index.mjs (100%) rename tests/manual_importmap/file_override_scope/{root => input}/node_modules/bar/button.css.js (100%) rename tests/manual_importmap/file_override_scope/{root => input}/node_modules/bar/package.json (100%) rename tests/manual_importmap/file_override_scope/{root => input}/node_modules/foo/index.mjs (100%) rename tests/manual_importmap/file_override_scope/{root => input}/node_modules/foo/package.json (100%) rename tests/manual_importmap/file_override_scope/{root => input}/package.json (100%) create mode 100644 tests/manual_importmap/file_override_scope/output/file_override_scope.md delete mode 100644 tests/manual_importmap/file_override_scope/root/test.importmap rename tests/manual_importmap/preact_override/{root => input}/index.js (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/preact/compat/index.js (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/preact/index.js (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/preact/package.json (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/react-redux/index.js (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/react-redux/package.json (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/react/index.js (100%) rename tests/manual_importmap/preact_override/{root => input}/node_modules/react/package.json (100%) rename tests/manual_importmap/preact_override/{root => input}/package.json (100%) create mode 100644 tests/manual_importmap/preact_override/output/preact_override.md delete mode 100644 tests/manual_importmap/preact_override/root/test.importmap diff --git a/.gitignore b/.gitignore index dcaf1195..b10e9b76 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,5 @@ .DS_Store **/git_ignored/ +/todo.txt 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 From 93b4fb900735b1104feaa890d47214fdb9efea58 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 14:10:03 +0200 Subject: [PATCH 30/33] update a test --- .../0_html_no_importmap}/index.html | 0 .../0_html_no_importmap}/main.js | 0 .../node_modules/foo/foo.js | 0 .../node_modules/foo/package.json | 0 .../0_html_no_importmap}/package.json | 0 .../index.html} | 0 .../fixtures/1_html_importmap_empty/main.js | 1 + .../node_modules/foo/foo.js | 1 + .../node_modules/foo/package.json | 5 ++ .../1_html_importmap_empty/package.json | 7 +++ .../index.html} | 0 .../fixtures/2_html_importmap_src/main.js | 1 + .../node_modules/foo/foo.js | 1 + .../node_modules/foo/package.json | 5 ++ .../2_html_importmap_src/package.json | 7 +++ .../fixtures/index_without_importmap.html | 12 ---- .../0_html_no_importmap.md} | 19 +++++- .../1_html_importmap_empty.md} | 19 +++++- .../2_html_importmap_src.md} | 24 +++++++- .../write_inside_html.test.mjs | 59 ++++++++----------- 20 files changed, 110 insertions(+), 51 deletions(-) rename tests/write_inside_html/{root => fixtures/0_html_no_importmap}/index.html (100%) rename tests/write_inside_html/{root => fixtures/0_html_no_importmap}/main.js (100%) rename tests/write_inside_html/{root => fixtures/0_html_no_importmap}/node_modules/foo/foo.js (100%) rename tests/write_inside_html/{root => fixtures/0_html_no_importmap}/node_modules/foo/package.json (100%) rename tests/write_inside_html/{root => fixtures/0_html_no_importmap}/package.json (100%) rename tests/write_inside_html/fixtures/{index_importmap_empty.html => 1_html_importmap_empty/index.html} (100%) create mode 100644 tests/write_inside_html/fixtures/1_html_importmap_empty/main.js create mode 100644 tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/foo.js create mode 100644 tests/write_inside_html/fixtures/1_html_importmap_empty/node_modules/foo/package.json create mode 100644 tests/write_inside_html/fixtures/1_html_importmap_empty/package.json rename tests/write_inside_html/fixtures/{index_importmap_with_src.html => 2_html_importmap_src/index.html} (100%) create mode 100644 tests/write_inside_html/fixtures/2_html_importmap_src/main.js create mode 100644 tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/foo.js create mode 100644 tests/write_inside_html/fixtures/2_html_importmap_src/node_modules/foo/package.json create mode 100644 tests/write_inside_html/fixtures/2_html_importmap_src/package.json delete mode 100644 tests/write_inside_html/fixtures/index_without_importmap.html rename tests/write_inside_html/{snapshots/index_without_importmap.html => output/0_html_no_importmap.md} (66%) rename tests/write_inside_html/{snapshots/index_importmap_empty.html => output/1_html_importmap_empty.md} (63%) rename tests/write_inside_html/{snapshots/index_importmap_with_src.html => output/2_html_importmap_src.md} (54%) 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_empty.html b/tests/write_inside_html/output/1_html_importmap_empty.md similarity index 63% rename from tests/write_inside_html/snapshots/index_importmap_empty.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_empty.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_with_src.html b/tests/write_inside_html/output/2_html_importmap_src.md similarity index 54% rename from tests/write_inside_html/snapshots/index_importmap_with_src.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_with_src.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 5eb837be..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 { copyFileSync } from "@jsenv/filesystem"; -import { takeDirectorySnapshot } from "@jsenv/snapshot"; - +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"); From 085c2cf101478b168036f524ae3f8164ccea452a Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 14:12:17 +0200 Subject: [PATCH 31/33] write a test --- .../deep_importmap/deep_importmap.test.mjs | 45 +++++++++---------- .../node_modules/example/file.js | 0 .../node_modules/example/index.js | 0 .../node_modules/example/package.json | 0 .../{root => input}/package.json | 0 .../{root => input}/src/directory/file.js | 0 .../{root => input}/src/directory/main.js | 0 .../deep_importmap/output/deep_importmap.md | 33 ++++++++++++++ .../root/src/directory/test.importmap | 11 ----- .../dependency_indirect.test.mjs | 34 +++++++------- .../{root => input}/index.js | 0 .../{root => input}/node_modules/a/index.js | 0 .../node_modules/a/package.json | 0 .../{root => input}/node_modules/b/index.js | 0 .../node_modules/b/package.json | 0 .../{root => input}/package.json | 0 .../output/dependency_indirect.md | 23 ++++++++++ .../dependency_indirect/root/test.importmap | 6 --- 18 files changed, 94 insertions(+), 58 deletions(-) rename tests/node_esm/deep_importmap/{root => input}/node_modules/example/file.js (100%) rename tests/node_esm/deep_importmap/{root => input}/node_modules/example/index.js (100%) rename tests/node_esm/deep_importmap/{root => input}/node_modules/example/package.json (100%) rename tests/node_esm/deep_importmap/{root => input}/package.json (100%) rename tests/node_esm/deep_importmap/{root => input}/src/directory/file.js (100%) rename tests/node_esm/deep_importmap/{root => input}/src/directory/main.js (100%) create mode 100644 tests/node_esm/deep_importmap/output/deep_importmap.md delete mode 100644 tests/node_esm/deep_importmap/root/src/directory/test.importmap rename tests/node_esm/dependency_indirect/{root => input}/index.js (100%) rename tests/node_esm/dependency_indirect/{root => input}/node_modules/a/index.js (100%) rename tests/node_esm/dependency_indirect/{root => input}/node_modules/a/package.json (100%) rename tests/node_esm/dependency_indirect/{root => input}/node_modules/b/index.js (100%) rename tests/node_esm/dependency_indirect/{root => input}/node_modules/b/package.json (100%) rename tests/node_esm/dependency_indirect/{root => input}/package.json (100%) create mode 100644 tests/node_esm/dependency_indirect/output/dependency_indirect.md delete mode 100644 tests/node_esm/dependency_indirect/root/test.importmap 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 From d86177e5b4ee853680710bc019aa1e53dddb19d9 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 14:15:07 +0200 Subject: [PATCH 32/33] migrate 2 more test and godo for now --- .../dev_and_prod/dev_and_prod.test.mjs | 37 ++++++------- .../{root => input}/node_modules/bar/bar.js | 0 .../node_modules/bar/package.json | 0 .../{root => input}/node_modules/foo/foo.js | 0 .../node_modules/foo/package.json | 0 .../dev_and_prod/{root => input}/package.json | 0 .../dev_and_prod/output/dev_and_prod.md | 55 +++++++++++++++++++ .../node_esm/dev_and_prod/root/dev.importmap | 11 ---- .../node_esm/dev_and_prod/root/prod.importmap | 9 --- 9 files changed, 72 insertions(+), 40 deletions(-) rename tests/node_esm/dev_and_prod/{root => input}/node_modules/bar/bar.js (100%) rename tests/node_esm/dev_and_prod/{root => input}/node_modules/bar/package.json (100%) rename tests/node_esm/dev_and_prod/{root => input}/node_modules/foo/foo.js (100%) rename tests/node_esm/dev_and_prod/{root => input}/node_modules/foo/package.json (100%) rename tests/node_esm/dev_and_prod/{root => input}/package.json (100%) create mode 100644 tests/node_esm/dev_and_prod/output/dev_and_prod.md delete mode 100644 tests/node_esm/dev_and_prod/root/dev.importmap delete mode 100644 tests/node_esm/dev_and_prod/root/prod.importmap 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 From ad3a5aa4bbd604855a5c257fabf09363be66ec88 Mon Sep 17 00:00:00 2001 From: dmail Date: Thu, 25 Jul 2024 14:18:01 +0200 Subject: [PATCH 33/33] new version --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 41342167..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": { @@ -40,7 +40,7 @@ "dependencies": { "@babel/core": "7.24.9", "@babel/traverse": "7.24.8", - "@jsenv/ast": "6.2.7", + "@jsenv/ast": "6.2.8", "@jsenv/filesystem": "4.9.4", "@jsenv/importmap": "1.2.1", "@jsenv/logger": "4.1.1", @@ -54,15 +54,15 @@ "@babel/plugin-syntax-jsx": "7.24.7", "@jsenv/assert": "4.1.6", "@jsenv/babel-preset": "1.1.3", - "@jsenv/core": "39.2.9", + "@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.5", "@jsenv/performance-impact": "4.2.1", "@jsenv/server": "15.2.15", - "@jsenv/snapshot": "2.6.0", - "@jsenv/test": "3.3.19", + "@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",