diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 725240a6bb..c380436e1a 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -70,6 +70,7 @@ const eslintConfig = composeEslintConfig( __filename: "off", __dirname: "off", require: "off", + exports: "off", }, overrides: [ { @@ -82,6 +83,7 @@ const eslintConfig = composeEslintConfig( __filename: true, __dirname: true, require: true, + exports: true, }, // inside *.cjs files, use commonjs module resolution settings: { diff --git a/experimental/commonjs_with_babel/convert_commonjs.js b/experimental/commonjs_with_babel/convert_commonjs.js index 3bc32a7c7f..15dd133f4f 100644 --- a/experimental/commonjs_with_babel/convert_commonjs.js +++ b/experimental/commonjs_with_babel/convert_commonjs.js @@ -1,5 +1,7 @@ +// eslint-disable-next-line no-undef exports.answer = process.env.NODE_ENV +// eslint-disable-next-line no-undef exports.setTimeout = global.setTimeout // eslint-disable-next-line no-undef diff --git a/jsconfig.json b/jsconfig.json index 06ab1f6aec..fc7db87a6c 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -318,7 +318,7 @@ "./node_modules/cssnano-preset-default/*" ], "istanbul-lib-instrument": [ - "./node_modules/istanbul-lib-instrument/dist/index.js" + "./node_modules/istanbul-lib-instrument/src/index.js" ], "postcss/lib/declaration": [ "./node_modules/postcss/lib/declaration.js" diff --git a/package.json b/package.json index 1f68f70c73..60911ae0e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/core", - "version": "21.0.3", + "version": "21.1.0", "description": "Tool to develop, test and build js projects", "license": "MIT", "repository": { @@ -57,7 +57,7 @@ "@babel/core": "7.15.5", "@babel/helper-module-imports": "7.15.4", "@babel/helpers": "7.15.4", - "@babel/parser": "7.15.6", + "@babel/parser": "7.15.7", "@babel/plugin-proposal-dynamic-import": "7.14.5", "@babel/plugin-proposal-json-strings": "7.14.5", "@babel/plugin-proposal-numeric-separator": "7.14.5", @@ -95,15 +95,15 @@ "@babel/plugin-transform-unicode-regex": "7.14.5", "@c88/v8-coverage": "0.1.1", "@jsenv/cancellation": "3.0.0", - "@jsenv/filesystem": "2.1.1", + "@jsenv/filesystem": "2.2.0", "@jsenv/import-map": "6.13.3", "@jsenv/logger": "4.0.1", "@jsenv/node-signals": "2.0.1", - "@jsenv/server": "7.1.0", + "@jsenv/server": "7.2.0", "@jsenv/uneval": "1.6.0", "@rollup/plugin-commonjs": "20.0.0", "@rollup/plugin-json": "4.1.0", - "@rollup/plugin-node-resolve": "13.0.4", + "@rollup/plugin-node-resolve": "13.0.5", "@rollup/plugin-replace": "3.0.0", "ansi-to-html": "0.7.1", "babel-plugin-transform-async-to-promises": "0.8.15", @@ -115,49 +115,49 @@ "html-minifier": "4.0.0", "humanize-duration": "3.27.0", "is-unicode-supported": "1.1.0", - "istanbul-lib-coverage": "3.0.0", - "istanbul-lib-instrument": "4.0.3", + "istanbul-lib-coverage": "3.0.1", + "istanbul-lib-instrument": "5.0.2", "istanbul-lib-report": "3.0.0", "istanbul-reports": "3.0.2", "magic-string": "0.25.7", "parse5": "6.0.1", - "playwright": "1.14.1", - "postcss": "8.3.6", + "playwright": "1.15.0", + "postcss": "8.3.8", "postcss-value-parser": "4.1.0", "regenerator-runtime": "0.13.9", - "rollup": "2.56.3", + "rollup": "2.57.0", "rollup-plugin-node-builtins-brofs": "2.1.3", "rollup-plugin-node-globals": "1.4.0", "source-map": "0.7.3", - "string-width": "5.0.0", + "string-width": "5.0.1", "supports-color": "9.0.2", "systemjs": "6.10.3", - "terser": "5.7.2", + "terser": "5.9.0", "tree-kill": "1.2.2", - "v8-to-istanbul": "8.0.0", - "wrap-ansi": "8.0.0" + "v8-to-istanbul": "8.1.0", + "wrap-ansi": "8.0.1" }, "devDependencies": { - "@babel/eslint-parser": "7.15.4", + "@babel/eslint-parser": "7.15.7", "@babel/plugin-transform-react-jsx": "7.14.9", "@babel/plugin-transform-typescript": "7.15.4", "@jsenv/assert": "2.3.1", "@jsenv/codecov-upload": "3.5.0", - "@jsenv/eslint-config": "16.0.1", + "@jsenv/eslint-config": "16.0.4", "@jsenv/github-release-package": "1.2.3", "@jsenv/importmap-eslint-resolver": "5.1.2", - "@jsenv/importmap-node-module": "2.2.0", + "@jsenv/importmap-node-module": "2.2.1", "@jsenv/node-module-import-map": "13.6.1", "@jsenv/package-publish": "1.6.2", "@jsenv/performance-impact": "1.7.0", "@jsenv/prettier-check-project": "5.6.1", "@jsenv/pwa": "4.0.0", "eslint": "7.32.0", - "eslint-plugin-html": "6.1.2", + "eslint-plugin-html": "6.2.0", "eslint-plugin-import": "2.24.2", "node-notifier": "10.0.0", "preact": "10.5.14", - "prettier": "2.4.0", + "prettier": "2.4.1", "react": "17.0.2", "redux": "4.1.1" } diff --git a/src/commonJsToJavaScriptModule.js b/src/commonJsToJavaScriptModule.js index d82779ef2c..846cbee30b 100644 --- a/src/commonJsToJavaScriptModule.js +++ b/src/commonJsToJavaScriptModule.js @@ -60,7 +60,11 @@ export const commonJsToJavaScriptModule = async ({ buffer: replaceBuffer, }) - const commonJsRollupPlugin = commonjs() + const commonJsRollupPlugin = commonjs({ + // esmExternals: true, + // defaultIsModuleExports: true, + // requireReturnsDefault: "namespace", + }) const rollupBuild = await rollup({ input: filePath, diff --git a/src/internal/building/buildUsingRollup.js b/src/internal/building/buildUsingRollup.js index 9a394103ec..ec630156c3 100644 --- a/src/internal/building/buildUsingRollup.js +++ b/src/internal/building/buildUsingRollup.js @@ -1,5 +1,11 @@ import { createOperation } from "@jsenv/cancellation" -import { urlToFileSystemPath, ensureEmptyDirectory } from "@jsenv/filesystem" +import { + urlToFileSystemPath, + ensureEmptyDirectory, + readFile, + urlToRelativeUrl, +} from "@jsenv/filesystem" +import { createDetailedMessage } from "@jsenv/logger" import { buildServiceWorker } from "@jsenv/core/src/internal/building/buildServiceWorker.js" import { createJsenvRollupPlugin } from "./createJsenvRollupPlugin.js" @@ -61,45 +67,50 @@ export const buildUsingRollup = async ({ runtimeSupport.safari, ) - const { jsenvRollupPlugin, getLastErrorMessage, getResult } = - await createJsenvRollupPlugin({ - cancellationToken, - logger, + const { + jsenvRollupPlugin, + getLastErrorMessage, + getResult, + asOriginalUrl, + asProjectUrl, + } = await createJsenvRollupPlugin({ + cancellationToken, + logger, - projectDirectoryUrl, - entryPointMap, - compileServerOrigin, - compileDirectoryRelativeUrl, - buildDirectoryUrl, - assetManifestFile, - assetManifestFileRelativeUrl, - writeOnFileSystem, + projectDirectoryUrl, + entryPointMap, + compileServerOrigin, + compileDirectoryRelativeUrl, + buildDirectoryUrl, + assetManifestFile, + assetManifestFileRelativeUrl, + writeOnFileSystem, - format, - systemJsUrl, - babelPluginMap, - transformTopLevelAwait, - node, - browser, - - urlMappings, - importResolutionMethod, - importMapFileRelativeUrl, - importDefaultExtension, - externalImportSpecifiers, - externalImportUrlPatterns, - importPaths, - - urlVersioning, - lineBreakNormalization, - jsConcatenation, - useImportMapToMaximizeCacheReuse, - - minify, - minifyJsOptions, - minifyCssOptions, - minifyHtmlOptions, - }) + format, + systemJsUrl, + babelPluginMap, + transformTopLevelAwait, + node, + browser, + + urlMappings, + importResolutionMethod, + importMapFileRelativeUrl, + importDefaultExtension, + externalImportSpecifiers, + externalImportUrlPatterns, + importPaths, + + urlVersioning, + lineBreakNormalization, + jsConcatenation, + useImportMapToMaximizeCacheReuse, + + minify, + minifyJsOptions, + minifyCssOptions, + minifyHtmlOptions, + }) try { await useRollup({ @@ -123,6 +134,25 @@ export const buildUsingRollup = async ({ } throw e } + if (e.code === "MISSING_EXPORT") { + let message = e.message + message = message.replace(e.id, (url) => asOriginalUrl(url)) + message = message.replace(/(www|http:|https:)+[^\s]+[\w]/g, (url) => + asOriginalUrl(url), + ) + const importedFileRollupUrl = e.message.match(/not exported by (.*?),/)[1] + const convertSuggestion = await getConvertSuggestion({ + importedFileRollupUrl, + asProjectUrl, + asOriginalUrl, + projectDirectoryUrl, + }) + const detailedMessage = createDetailedMessage(message, { + frame: e.frame, + ...convertSuggestion, + }) + throw new Error(detailedMessage, { cause: e }) + } throw e } @@ -248,3 +278,33 @@ const formatToRollupFormat = (format) => { if (format === "esmodule") return "esm" throw new Error(`unexpected format, got ${format}`) } + +const getConvertSuggestion = async ({ + importedFileRollupUrl, + asProjectUrl, + asOriginalUrl, + projectDirectoryUrl, +}) => { + const importedFileUrl = asProjectUrl(importedFileRollupUrl) + const importedFileContent = await readFile(importedFileUrl) + const looksLikeCommonJs = + importedFileContent.includes("module.exports = ") || + importedFileContent.includes("exports.") + + if (!looksLikeCommonJs) { + return null + } + + const importerFileOriginalUrl = asOriginalUrl(importedFileUrl) + const importedFileOriginalRelativeUrl = urlToRelativeUrl( + importerFileOriginalUrl, + projectDirectoryUrl, + ) + return { + suggestion: `The file seems written in commonjs, you should use "customCompiler" to convert it to js module +{ + "./${importedFileOriginalRelativeUrl}": commonJsToJavaScriptModule +} +As documented in https://github.com/jsenv/jsenv-core/blob/master/docs/shared-parameters.md#customcompilers`, + } +} diff --git a/src/internal/building/createJsenvRollupPlugin.js b/src/internal/building/createJsenvRollupPlugin.js index af6c9ac5c8..33f1929c68 100644 --- a/src/internal/building/createJsenvRollupPlugin.js +++ b/src/internal/building/createJsenvRollupPlugin.js @@ -167,6 +167,8 @@ export const createJsenvRollupPlugin = async ({ let ressourceBuilder let rollupEmitFile = () => {} let rollupSetAssetSource = () => {} + let _rollupGetModuleInfo = () => {} + const rollupGetModuleInfo = (id) => _rollupGetModuleInfo(id) let importResolver const emitAsset = ({ fileName, source }) => { @@ -228,6 +230,7 @@ building ${entryFileRelativeUrls.length} entry files...`) // https://rollupjs.org/guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string rollupEmitFile = (...args) => this.emitFile(...args) rollupSetAssetSource = (...args) => this.setAssetSource(...args) + _rollupGetModuleInfo = (id) => this.getModuleInfo(id) let importMapInfoFromHtml = null if (htmlEntryPointCount === 1) { @@ -1176,6 +1179,9 @@ non-js ressources can be used with new URL("${urlRelativeToImporter}", import.me buildStats, } }, + asOriginalUrl, + asProjectUrl, + rollupGetModuleInfo, } } diff --git a/test/async-await/async-await-build-commonjs-untransformed/async-await-build-commonjs-untransformed.js b/test/async_await/async_await.js similarity index 100% rename from test/async-await/async-await-build-commonjs-untransformed/async-await-build-commonjs-untransformed.js rename to test/async_await/async_await.js diff --git a/test/build_async_await_commonjs/build_async_await_commonjs.test.js b/test/async_await/async_await_build_commonjs.test.js similarity index 82% rename from test/build_async_await_commonjs/build_async_await_commonjs.test.js rename to test/async_await/async_await_build_commonjs.test.js index 026b28b0a9..81e9654dd6 100644 --- a/test/build_async_await_commonjs/build_async_await_commonjs.test.js +++ b/test/async_await/async_await_build_commonjs.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -18,13 +14,11 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/commonjs` const entryPointMap = { - [`./${testDirectoryRelativeUrl}${testDirectoryname}.js`]: "./main.cjs", + [`./${testDirectoryRelativeUrl}async_await.js`]: "./main.cjs", } - await buildProject({ ...GENERATE_COMMONJS_BUILD_TEST_PARAMS, jsenvDirectoryRelativeUrl, diff --git a/test/async-await/async-await-build-commonjs-untransformed/async-await-build-commonjs-untransformed.test.js b/test/async_await/async_await_build_commonjs_untransformed.test.js similarity index 78% rename from test/async-await/async-await-build-commonjs-untransformed/async-await-build-commonjs-untransformed.test.js rename to test/async_await/async_await_build_commonjs_untransformed.test.js index 8c8168fd23..610b553253 100644 --- a/test/async-await/async-await-build-commonjs-untransformed/async-await-build-commonjs-untransformed.test.js +++ b/test/async_await/async_await_build_commonjs_untransformed.test.js @@ -1,6 +1,6 @@ -import { basename } from "path" import { assert } from "@jsenv/assert" import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" import { requireCommonJsBuild } from "@jsenv/core/test/requireCommonJsBuild.js" @@ -14,14 +14,11 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = basename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/commonjs` -const mainFilename = `${testDirectoryname}.js` const entryPointMap = { - [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.cjs", + [`./${testDirectoryRelativeUrl}async_await.js`]: "./main.cjs", } - await buildProject({ ...GENERATE_COMMONJS_BUILD_TEST_PARAMS, babelPluginMap: {}, @@ -29,12 +26,11 @@ await buildProject({ buildDirectoryRelativeUrl, entryPointMap, }) -const { - namespace: { ask }, -} = await requireCommonJsBuild({ +const { namespace } = await requireCommonJsBuild({ ...REQUIRE_COMMONJS_BUILD_TEST_PARAMS, buildDirectoryRelativeUrl, }) -const actual = await ask() + +const actual = await namespace.ask() const expected = 42 assert({ actual, expected }) diff --git a/test/build_async_await_commonjs/build_async_await_commonjs.js b/test/build_async_await_commonjs/build_async_await_commonjs.js deleted file mode 100644 index b85a9c7220..0000000000 --- a/test/build_async_await_commonjs/build_async_await_commonjs.js +++ /dev/null @@ -1,4 +0,0 @@ -export const ask = async () => { - const value = await Promise.resolve(42) - return value -} diff --git a/test/build_module_force_inline_systemjs/build_module_force_inline_systemjs.html b/test/build_module_force_inline/build_module_force_inline.html similarity index 100% rename from test/build_module_force_inline_systemjs/build_module_force_inline_systemjs.html rename to test/build_module_force_inline/build_module_force_inline.html diff --git a/test/build_module_force_inline_systemjs/build_module_force_inline_systemjs.test.js b/test/build_module_force_inline/build_module_force_inline_systemjs.test.js similarity index 90% rename from test/build_module_force_inline_systemjs/build_module_force_inline_systemjs.test.js rename to test/build_module_force_inline/build_module_force_inline_systemjs.test.js index 4e6b48f698..88c59f1af6 100644 --- a/test/build_module_force_inline_systemjs/build_module_force_inline_systemjs.test.js +++ b/test/build_module_force_inline/build_module_force_inline_systemjs.test.js @@ -4,7 +4,6 @@ import { urlToRelativeUrl, readFile, resolveUrl, - urlToBasename, } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" @@ -25,14 +24,13 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/systemjs/` -const mainFilename = `${testDirectoryname}.html` +const mainFilename = `build_module_force_inline.html` const entryPointMap = { [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.html", } -await buildProject({ +const { buildMappings } = await buildProject({ ...GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, // logLevel: "info", jsenvDirectoryRelativeUrl, @@ -72,8 +70,8 @@ const htmlString = await readFile(htmlBuildUrl) srcAttribute: undefined, mappings: { imports: { - "./file.js": "./file-ec1c9738.js", - "./main.js": "./main-007250a8.js", + "./file.js": `./${buildMappings[`${testDirectoryRelativeUrl}file.js`]}`, + "./main.js": `./main-fddc88f1.js`, // should not here because was inlined but that's ok }, }, } diff --git a/test/build_module_force_inline_systemjs/file.js b/test/build_module_force_inline/file.js similarity index 100% rename from test/build_module_force_inline_systemjs/file.js rename to test/build_module_force_inline/file.js diff --git a/test/build_module_force_inline_systemjs/main.js b/test/build_module_force_inline/main.js similarity index 100% rename from test/build_module_force_inline_systemjs/main.js rename to test/build_module_force_inline/main.js diff --git a/test/build_module_force_inline_systemjs/project.importmap b/test/build_module_force_inline/project.importmap similarity index 100% rename from test/build_module_force_inline_systemjs/project.importmap rename to test/build_module_force_inline/project.importmap diff --git a/test/build_modulepreload/build_modulepreload.test.js b/test/build_modulepreload/build_modulepreload_esmodule.test.js similarity index 85% rename from test/build_modulepreload/build_modulepreload.test.js rename to test/build_modulepreload/build_modulepreload_esmodule.test.js index af0479af44..a8f4803340 100644 --- a/test/build_modulepreload/build_modulepreload.test.js +++ b/test/build_modulepreload/build_modulepreload_esmodule.test.js @@ -1,10 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveUrl, - urlToRelativeUrl, - urlToBasename, - readFile, -} from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl, readFile } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -19,11 +14,10 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` const entryPointMap = { - [`./${testDirectoryRelativeUrl}${testDirectoryname}.html`]: "./main.html", + [`./${testDirectoryRelativeUrl}build_modulepreload.html`]: "./main.html", } const { buildMappings } = await buildProject({ diff --git a/test/build_modulepreload/build_modulepreload_systemjs.test.js b/test/build_modulepreload/build_modulepreload_systemjs.test.js index 0ff806a747..6b3b17b44c 100644 --- a/test/build_modulepreload/build_modulepreload_systemjs.test.js +++ b/test/build_modulepreload/build_modulepreload_systemjs.test.js @@ -1,10 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveUrl, - urlToRelativeUrl, - urlToBasename, - readFile, -} from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl, readFile } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -19,13 +14,12 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/systemjs/` const entryPointMap = { - [`./${testDirectoryRelativeUrl}${testDirectoryname}.html`]: "./main.html", + [`./${testDirectoryRelativeUrl}build_modulepreload.html`]: "./main.html", } -await buildProject({ +const { buildMappings } = await buildProject({ ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, jsenvDirectoryRelativeUrl, buildDirectoryRelativeUrl, @@ -52,7 +46,7 @@ await buildProject({ } const expected = { rel: "preload", - href: "main-2f012c65.js", + href: buildMappings[`${testDirectoryRelativeUrl}main.js`], } assert({ actual, expected }) } diff --git a/test/build_top_level_await_systemjs/build_top_level_await_systemjs.js b/test/build_top_level_await_systemjs/build_top_level_await_systemjs.js deleted file mode 100644 index cccb446fd1..0000000000 --- a/test/build_top_level_await_systemjs/build_top_level_await_systemjs.js +++ /dev/null @@ -1 +0,0 @@ -export const value = await Promise.resolve(42) diff --git a/test/build_top_level_await_systemjs/index.html b/test/build_top_level_await_systemjs/index.html deleted file mode 100644 index 99daaa9abc..0000000000 --- a/test/build_top_level_await_systemjs/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - Test - - - - - - diff --git a/test/coverage/coverage_error_syntax/coverage_error_syntax.js b/test/coverage/coverage_error_syntax/coverage_error_syntax.js deleted file mode 100644 index dbb3555c6c..0000000000 --- a/test/coverage/coverage_error_syntax/coverage_error_syntax.js +++ /dev/null @@ -1 +0,0 @@ -const a = ( \ No newline at end of file diff --git a/test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.js b/test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.js deleted file mode 100644 index f85dde4152..0000000000 --- a/test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.js +++ /dev/null @@ -1 +0,0 @@ -export const value = import("./answer.js") diff --git a/test/dynamic-import/dynamic-import-build-global/answer.js b/test/dynamic-import/dynamic-import-build-global/answer.js deleted file mode 100644 index 02f8a32637..0000000000 --- a/test/dynamic-import/dynamic-import-build-global/answer.js +++ /dev/null @@ -1 +0,0 @@ -export default 42 diff --git a/test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.js b/test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.js deleted file mode 100644 index 5e25ca6fc9..0000000000 --- a/test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.js +++ /dev/null @@ -1,2 +0,0 @@ -const { default: value } = await import("./answer.js") -export default value diff --git a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.js b/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.js deleted file mode 100644 index 68bba2a290..0000000000 --- a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.js +++ /dev/null @@ -1,2 +0,0 @@ -const { default: value } = await import("./src/answer.js") -export default value diff --git a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.node.xtest.js b/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.node.xtest.js deleted file mode 100644 index 8a376aebb9..0000000000 --- a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.node.xtest.js +++ /dev/null @@ -1,56 +0,0 @@ -// disabled because it needs --experimental-import-meta-resolve to work - -import { basename } from "path" -import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" -import { buildProject } from "@jsenv/core" -import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" -import { - GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, - IMPORT_SYSTEM_JS_BUILD_TEST_PARAMS, -} from "@jsenv/core/test/TEST_PARAMS_BUILD_SYSTEMJS.js" -import { nodeImportSystemJsBuild } from "@jsenv/core/test/nodeImportSystemJsBuild.js" - -const testDirectoryUrl = resolveUrl("./", import.meta.url) -const testDirectoryRelativeUrl = urlToRelativeUrl( - testDirectoryUrl, - jsenvCoreDirectoryUrl, -) -const testDirectoryname = basename(testDirectoryRelativeUrl) -const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/systemjs/` -const mainFilename = `${testDirectoryname}.js` - -const firstBuild = await buildProject({ - ...GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, - useImportMapToMaximizeCacheReuse: false, - jsenvDirectoryRelativeUrl, - buildDirectoryRelativeUrl, - entryPointMap: { - [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.js", - }, -}) -const { namespace: actual } = await nodeImportSystemJsBuild({ - ...IMPORT_SYSTEM_JS_BUILD_TEST_PARAMS, - testDirectoryRelativeUrl, -}) -const expected = { - default: 42, -} -assert({ actual, expected }) - -// ensure file hash does not change when runned twice -{ - const secondBuild = await buildProject({ - ...GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, - useImportMapToMaximizeCacheReuse: false, - jsenvDirectoryRelativeUrl, - buildDirectoryRelativeUrl, - entryPointMap: { - [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.js", - }, - }) - const actual = secondBuild.buildMappings - const expected = firstBuild.buildMappings - assert({ actual, expected }) -} diff --git a/test/dynamic-import/dynamic-import-build-systemjs/index.html b/test/dynamic-import/dynamic-import-build-systemjs/index.html deleted file mode 100644 index 99daaa9abc..0000000000 --- a/test/dynamic-import/dynamic-import-build-systemjs/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - Test - - - - - - diff --git a/test/dynamic-import/dynamic-import-build-systemjs/src/answer.js b/test/dynamic-import/dynamic-import-build-systemjs/src/answer.js deleted file mode 100644 index 02f8a32637..0000000000 --- a/test/dynamic-import/dynamic-import-build-systemjs/src/answer.js +++ /dev/null @@ -1 +0,0 @@ -export default 42 diff --git a/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.html b/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.html deleted file mode 100644 index c9e7dd7257..0000000000 --- a/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/test/dynamic-import/dynamic-import-launch-node/dependency.js b/test/dynamic-import/dynamic-import-launch-node/dependency.js deleted file mode 100644 index eab39ce89c..0000000000 --- a/test/dynamic-import/dynamic-import-launch-node/dependency.js +++ /dev/null @@ -1 +0,0 @@ -export const answer = 42 diff --git a/test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.js b/test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.js deleted file mode 100644 index e5f49cdf8b..0000000000 --- a/test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.js +++ /dev/null @@ -1,3 +0,0 @@ -const { answer } = await import("./dependency.js") - -export default answer diff --git a/test/dynamic-import/dynamic-import-launch-browser/dependency.js b/test/dynamic_import/dependency.js similarity index 100% rename from test/dynamic-import/dynamic-import-launch-browser/dependency.js rename to test/dynamic_import/dependency.js diff --git a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.html b/test/dynamic_import/dynamic_import.html similarity index 61% rename from test/error-stack/error-stack-launch-browser/error-stack-launch-browser.html rename to test/dynamic_import/dynamic_import.html index 4c61fbf2a7..a7cc5b6e02 100644 --- a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.html +++ b/test/dynamic_import/dynamic_import.html @@ -4,6 +4,6 @@ - + diff --git a/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.js b/test/dynamic_import/dynamic_import.js similarity index 100% rename from test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.js rename to test/dynamic_import/dynamic_import.js diff --git a/test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.test.js b/test/dynamic_import/dynamic_import_build_commonjs.test.js similarity index 82% rename from test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.test.js rename to test/dynamic_import/dynamic_import_build_commonjs.test.js index 9d54ade671..8e2e89bd4a 100644 --- a/test/dynamic-import/dynamic-import-build-commonjs/dynamic-import-build-commonjs.test.js +++ b/test/dynamic_import/dynamic_import_build_commonjs.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -18,11 +14,9 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/commonjs` -const mainFilename = `${testDirectoryname}.js` - +const mainFilename = `dynamic_import_without_top_level_await.js` await buildProject({ ...GENERATE_COMMONJS_BUILD_TEST_PARAMS, jsenvDirectoryRelativeUrl, @@ -37,5 +31,5 @@ const { namespace } = await requireCommonJsBuild({ buildDirectoryRelativeUrl, }) const actual = await namespace.value -const expected = { default: 42 } +const expected = { answer: 42 } assert({ actual, expected }) diff --git a/test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.test.js b/test/dynamic_import/dynamic_import_build_global.test.js similarity index 79% rename from test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.test.js rename to test/dynamic_import/dynamic_import_build_global.test.js index 915ebf2f23..6927afd5b8 100644 --- a/test/dynamic-import/dynamic-import-build-global/dynamic-import-build-global.test.js +++ b/test/dynamic_import/dynamic_import_build_global.test.js @@ -1,6 +1,6 @@ -import { basename } from "path" import { assert } from "@jsenv/assert" import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" + import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" import { GENERATE_GLOBAL_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_GLOBAL.js" @@ -10,10 +10,9 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = basename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/global/` -const mainFilename = `${testDirectoryname}.js` +const mainFilename = `dynamic_import_without_top_level_await.js` try { await buildProject({ @@ -26,8 +25,9 @@ try { }) } catch (actual) { const expected = new Error( - "UMD and IIFE output formats are not supported for code-splitting builds.", + `Invalid value "iife" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.`, ) expected.code = "INVALID_OPTION" + expected.url = "https://rollupjs.org/guide/en/#outputformat" assert({ actual, expected }) } diff --git a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.browser.test.js b/test/dynamic_import/dynamic_import_build_systemjs.browser.test.js similarity index 69% rename from test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.browser.test.js rename to test/dynamic_import/dynamic_import_build_systemjs.browser.test.js index 48370342d3..d1ba86a491 100644 --- a/test/dynamic-import/dynamic-import-build-systemjs/dynamic-import-build-systemjs.browser.test.js +++ b/test/dynamic_import/dynamic_import_build_systemjs.browser.test.js @@ -1,5 +1,5 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -14,25 +14,28 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/systemjs/` -const mainFilename = `${testDirectoryname}.js` +const mainFilename = `dynamic_import.html` -await buildProject({ +const { buildMappings } = await buildProject({ ...GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, useImportMapToMaximizeCacheReuse: false, jsenvDirectoryRelativeUrl, buildDirectoryRelativeUrl, entryPointMap: { - [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.js", + [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.html", }, }) -const { namespace: actual } = await browserImportSystemJsBuild({ +const mainBuildRelativeUrl = + buildMappings[`${testDirectoryRelativeUrl}dynamic_import.js`] +const { namespace } = await browserImportSystemJsBuild({ ...IMPORT_SYSTEM_JS_BUILD_TEST_PARAMS, testDirectoryRelativeUrl, - htmlFileRelativeUrl: "./index.html", + mainRelativeUrl: `./${mainBuildRelativeUrl}`, }) + +const actual = namespace const expected = { default: 42, } diff --git a/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.test.js b/test/dynamic_import/dynamic_import_launch_browser.test.js similarity index 84% rename from test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.test.js rename to test/dynamic_import/dynamic_import_launch_browser.test.js index 080f96a7b2..4b15ce4d9c 100644 --- a/test/dynamic-import/dynamic-import-launch-browser/dynamic-import-launch-browser.test.js +++ b/test/dynamic_import/dynamic_import_launch_browser.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchChromium, launchFirefox, launchWebkit } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -21,9 +17,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` -const filename = `${testDirectoryname}.html` +const filename = `dynamic_import.html` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ @@ -32,7 +27,12 @@ const { origin: compileServerOrigin, outDirectoryRelativeUrl } = }) await launchBrowsers( - [launchChromium, launchFirefox, launchWebkit], + [ + // comment to force-multiline + launchChromium, + launchFirefox, + launchWebkit, + ], async (launchBrowser) => { const actual = await launchAndExecute({ ...EXECUTION_TEST_PARAMS, @@ -49,7 +49,7 @@ await launchBrowsers( const expected = { status: "completed", namespace: { - "./dynamic-import-launch-browser.js": { + "./dynamic_import.js": { status: "completed", namespace: { default: 42, diff --git a/test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.test.js b/test/dynamic_import/dynamic_import_launch_node.test.js similarity index 86% rename from test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.test.js rename to test/dynamic_import/dynamic_import_launch_node.test.js index edecd7d516..b10978bb30 100644 --- a/test/dynamic-import/dynamic-import-launch-node/dynamic-import-launch-node.test.js +++ b/test/dynamic_import/dynamic_import_launch_node.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -20,9 +16,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.js` +const filename = `dynamic_import.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ diff --git a/test/dynamic_import/dynamic_import_without_top_level_await.js b/test/dynamic_import/dynamic_import_without_top_level_await.js new file mode 100644 index 0000000000..45379622b0 --- /dev/null +++ b/test/dynamic_import/dynamic_import_without_top_level_await.js @@ -0,0 +1 @@ +export const value = import("./dependency.js") diff --git a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.js b/test/error-runtime/error-runtime-exploring/error-runtime-exploring.js deleted file mode 100644 index bc7c17e39d..0000000000 --- a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.js +++ /dev/null @@ -1,3 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -triggerError() diff --git a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.html b/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.html deleted file mode 100644 index 05a9de7c0b..0000000000 --- a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Title - - - - - - - - diff --git a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.js b/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.js deleted file mode 100644 index 38a55a671d..0000000000 --- a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.js +++ /dev/null @@ -1,5 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -setTimeout(() => { - triggerError() -}, 1000) diff --git a/test/error-runtime/error-runtime-late-launch-browser/trigger-error.js b/test/error-runtime/error-runtime-late-launch-browser/trigger-error.js deleted file mode 100644 index 5d46853683..0000000000 --- a/test/error-runtime/error-runtime-late-launch-browser/trigger-error.js +++ /dev/null @@ -1,3 +0,0 @@ -export const triggerError = () => { - throw new Error("error") -} diff --git a/test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.js b/test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.js deleted file mode 100644 index 38a55a671d..0000000000 --- a/test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.js +++ /dev/null @@ -1,5 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -setTimeout(() => { - triggerError() -}, 1000) diff --git a/test/error-runtime/error-runtime-late-launch-node/trigger-error.js b/test/error-runtime/error-runtime-late-launch-node/trigger-error.js deleted file mode 100644 index 5d46853683..0000000000 --- a/test/error-runtime/error-runtime-late-launch-node/trigger-error.js +++ /dev/null @@ -1,3 +0,0 @@ -export const triggerError = () => { - throw new Error("error") -} diff --git a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.js b/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.js deleted file mode 100644 index bc7c17e39d..0000000000 --- a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.js +++ /dev/null @@ -1,3 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -triggerError() diff --git a/test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.js b/test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.js deleted file mode 100644 index bc7c17e39d..0000000000 --- a/test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.js +++ /dev/null @@ -1,3 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -triggerError() diff --git a/test/error-runtime/error-runtime-launch-node/trigger-error.js b/test/error-runtime/error-runtime-launch-node/trigger-error.js deleted file mode 100644 index 6dff06d252..0000000000 --- a/test/error-runtime/error-runtime-launch-node/trigger-error.js +++ /dev/null @@ -1,3 +0,0 @@ -export const triggerError = () => { - throw new Error("SPECIAL_STRING_UNLIKELY_TO_COLLIDE") -} diff --git a/test/error-runtime/error-runtime-testing-node/file.js b/test/error-runtime/error-runtime-testing-node/file.js deleted file mode 100644 index abad4635f4..0000000000 --- a/test/error-runtime/error-runtime-testing-node/file.js +++ /dev/null @@ -1 +0,0 @@ -export const ask = () => 40 diff --git a/test/error-runtime/error-runtime-testing-node/file.spec.js b/test/error-runtime/error-runtime-testing-node/file.spec.js deleted file mode 100644 index 6a29da8375..0000000000 --- a/test/error-runtime/error-runtime-testing-node/file.spec.js +++ /dev/null @@ -1,7 +0,0 @@ -import { ask } from "./file.js" - -const actual = ask() -const expected = 42 -if (actual !== expected) { - throw new Error(`ask() should return ${expected}, got ${actual}`) -} diff --git a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.js b/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.js deleted file mode 100644 index bc7c17e39d..0000000000 --- a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.js +++ /dev/null @@ -1,3 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -triggerError() diff --git a/test/error-stack/error-stack-launch-browser/trigger-error.js b/test/error-stack/error-stack-launch-browser/trigger-error.js deleted file mode 100644 index 5d46853683..0000000000 --- a/test/error-stack/error-stack-launch-browser/trigger-error.js +++ /dev/null @@ -1,3 +0,0 @@ -export const triggerError = () => { - throw new Error("error") -} diff --git a/test/error-stack/error-stack-launch-node/error-stack-launch-node.js b/test/error-stack/error-stack-launch-node/error-stack-launch-node.js deleted file mode 100644 index bc7c17e39d..0000000000 --- a/test/error-stack/error-stack-launch-node/error-stack-launch-node.js +++ /dev/null @@ -1,3 +0,0 @@ -import { triggerError } from "./trigger-error.js" - -triggerError() diff --git a/test/error-stack/error-stack-launch-node/trigger-error.js b/test/error-stack/error-stack-launch-node/trigger-error.js deleted file mode 100644 index 5d46853683..0000000000 --- a/test/error-stack/error-stack-launch-node/trigger-error.js +++ /dev/null @@ -1,3 +0,0 @@ -export const triggerError = () => { - throw new Error("error") -} diff --git a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.html b/test/error_runtime/error_runtime.html similarity index 65% rename from test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.html rename to test/error_runtime/error_runtime.html index b3b41f1797..a410f21072 100644 --- a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.html +++ b/test/error_runtime/error_runtime.html @@ -6,6 +6,6 @@ - + diff --git a/test/error_runtime/error_runtime.js b/test/error_runtime/error_runtime.js new file mode 100644 index 0000000000..a18cc56dae --- /dev/null +++ b/test/error_runtime/error_runtime.js @@ -0,0 +1,3 @@ +import { triggerError } from "./trigger_error.js" + +triggerError() diff --git a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.html b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.html similarity index 72% rename from test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.html rename to test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.html index cb32dc780e..88e42a57f7 100644 --- a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.html +++ b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.html @@ -7,6 +7,6 @@ - + diff --git a/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.js b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.js new file mode 100644 index 0000000000..22e58c7b5c --- /dev/null +++ b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout.js @@ -0,0 +1,5 @@ +import { triggerError } from "./trigger_error.js" + +setTimeout(() => { + triggerError() +}, 1000) diff --git a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.test.js b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_browser.test.js similarity index 88% rename from test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.test.js rename to test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_browser.test.js index 66798ed889..fdfc7dda65 100644 --- a/test/error-runtime/error-runtime-late-launch-browser/error-runtime-late-launch-browser.test.js +++ b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_browser.test.js @@ -1,10 +1,6 @@ import { createCancellationSource } from "@jsenv/cancellation" import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchChromium } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -21,9 +17,8 @@ const testDirectoryRelativePath = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryBasename = urlToBasename(testDirectoryRelativePath) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativePath}.jsenv/` -const filename = `${testDirectoryBasename}.html` +const filename = `error_runtime_after_timeout.html` const fileRelativeUrl = `${testDirectoryRelativePath}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ @@ -57,7 +52,7 @@ const actual = await launchAndExecute({ const expected = { status: "completed", namespace: { - [`./${testDirectoryBasename}.js`]: { + [`./error_runtime_after_timeout.js`]: { status: "completed", namespace: {}, }, diff --git a/test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.test.js b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_node.test.js similarity index 89% rename from test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.test.js rename to test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_node.test.js index ac442d31bd..d4b0ee0d53 100644 --- a/test/error-runtime/error-runtime-late-launch-node/error-runtime-late-launch-node.test.js +++ b/test/error_runtime/error_runtime_after_timeout/error_runtime_after_timeout_launch_node.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -20,9 +16,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.js` +const filename = `error_runtime_after_timeout.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ diff --git a/test/error-runtime/error-runtime-exploring/trigger-error.js b/test/error_runtime/error_runtime_after_timeout/trigger_error.js similarity index 100% rename from test/error-runtime/error-runtime-exploring/trigger-error.js rename to test/error_runtime/error_runtime_after_timeout/trigger_error.js diff --git a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.test.js b/test/error_runtime/error_runtime_exploring.test.js similarity index 81% rename from test/error-runtime/error-runtime-exploring/error-runtime-exploring.test.js rename to test/error_runtime/error_runtime_exploring.test.js index e4402f004c..faeb725b92 100644 --- a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.test.js +++ b/test/error_runtime/error_runtime_exploring.test.js @@ -1,5 +1,5 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { startExploring } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -11,9 +11,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.html` +const filename = `error_runtime.html` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const compileId = "best" @@ -44,12 +43,12 @@ browser.close() startTime: assert.any(Number), endTime: assert.any(Number), fileExecutionResultMap: { - [`./${testDirectoryname}.js`]: { + [`./error_runtime.js`]: { status: "errored", exceptionSource: assert.any(String), }, }, - error: Object.assign(new Error("error"), { + error: Object.assign(new Error("SPECIAL_STRING_UNLIKELY_TO_COLLIDE"), { filename: actual.executionResult.error.filename, lineno: actual.executionResult.error.lineno, columnno: actual.executionResult.error.columnno, @@ -61,18 +60,18 @@ browser.close() { const stack = executionResult.error.stack - const expected = `Error: error - at triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}trigger-error.js:2:9) - at Object.triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}${testDirectoryname}.js:3:1)` + const expected = `Error: SPECIAL_STRING_UNLIKELY_TO_COLLIDE + at triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}trigger_error.js:2:9) + at Object.triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}error_runtime.js:3:1)` const actual = stack.slice(0, expected.length) assert({ actual, expected }) } { const stack = pageLogs[0].text - const expected = `Error: error - at triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}trigger-error.js:2:9) - at Object.triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}${testDirectoryname}.js:3:1)` + const expected = `Error: SPECIAL_STRING_UNLIKELY_TO_COLLIDE + at triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}trigger_error.js:2:9) + at Object.triggerError (${exploringServer.origin}/${testDirectoryRelativeUrl}error_runtime.js:3:1)` const actual = stack.slice(0, expected.length) assert({ actual, expected }) } diff --git a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.test.js b/test/error_runtime/error_runtime_launch_browser.test.js similarity index 69% rename from test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.test.js rename to test/error_runtime/error_runtime_launch_browser.test.js index 2d8a08242a..63c2b406e0 100644 --- a/test/error-runtime/error-runtime-launch-browser/error-runtime-launch-browser.test.js +++ b/test/error_runtime/error_runtime_launch_browser.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchChromium, launchFirefox, launchWebkit } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -21,9 +17,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryBasename = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryBasename}.html` +const filename = `error_runtime.html` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ @@ -55,6 +50,7 @@ await launchBrowsers( }, captureConsole: true, }) + const actual = { status: result.status, errorMessage: result.error.message, @@ -64,5 +60,25 @@ await launchBrowsers( errorMessage: "SPECIAL_STRING_UNLIKELY_TO_COLLIDE", } assert({ actual, expected }) + + // error stack + { + const stack = result.error.stack + if (launchBrowser === launchChromium) { + const expected = `Error: SPECIAL_STRING_UNLIKELY_TO_COLLIDE + at triggerError (${testDirectoryUrl}trigger_error.js:2:9) + at ${testDirectoryUrl}error_runtime.js:3:1` + const actual = stack.slice(0, expected.length) + assert({ actual, expected }) + } else if (launchBrowser === launchFirefox) { + const expected = `Error: SPECIAL_STRING_UNLIKELY_TO_COLLIDE` + const actual = stack.slice(0, expected.length) + assert({ actual, expected }) + } else { + const actual = typeof stack + const expected = `string` + assert({ actual, expected }) + } + } }, ) diff --git a/test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.test.js b/test/error_runtime/error_runtime_launch_node.test.js similarity index 81% rename from test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.test.js rename to test/error_runtime/error_runtime_launch_node.test.js index e28f28e229..5922b75faa 100644 --- a/test/error-runtime/error-runtime-launch-node/error-runtime-launch-node.test.js +++ b/test/error_runtime/error_runtime_launch_node.test.js @@ -1,5 +1,5 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -16,9 +16,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.js` +const filename = `error_runtime.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ @@ -55,3 +54,12 @@ const expected = { consoleCallsContainsString: false, } assert({ actual, expected }) + +{ + const stack = result.error.stack + const expected = `Error: SPECIAL_STRING_UNLIKELY_TO_COLLIDE + at triggerError (${testDirectoryUrl}trigger_error.js:2:9) + at ${testDirectoryUrl}error_runtime.js:3:1` + const actual = stack.slice(0, expected.length) + assert({ actual, expected }) +} diff --git a/test/error-runtime/error-runtime-testing-browser/error-runtime-testing-browser.test.js b/test/error_runtime/error_runtime_testing/error_runtime_testing_browser.test.js similarity index 100% rename from test/error-runtime/error-runtime-testing-browser/error-runtime-testing-browser.test.js rename to test/error_runtime/error_runtime_testing/error_runtime_testing_browser.test.js diff --git a/test/error-runtime/error-runtime-testing-node/error-runtime-testing-node.test.js b/test/error_runtime/error_runtime_testing/error_runtime_testing_node.test.js similarity index 100% rename from test/error-runtime/error-runtime-testing-node/error-runtime-testing-node.test.js rename to test/error_runtime/error_runtime_testing/error_runtime_testing_node.test.js diff --git a/test/error-runtime/error-runtime-testing-browser/file.js b/test/error_runtime/error_runtime_testing/file.js similarity index 100% rename from test/error-runtime/error-runtime-testing-browser/file.js rename to test/error_runtime/error_runtime_testing/file.js diff --git a/test/error-runtime/error-runtime-testing-browser/file.spec.html b/test/error_runtime/error_runtime_testing/file.spec.html similarity index 100% rename from test/error-runtime/error-runtime-testing-browser/file.spec.html rename to test/error_runtime/error_runtime_testing/file.spec.html diff --git a/test/error-runtime/error-runtime-testing-browser/file.spec.js b/test/error_runtime/error_runtime_testing/file.spec.js similarity index 100% rename from test/error-runtime/error-runtime-testing-browser/file.spec.js rename to test/error_runtime/error_runtime_testing/file.spec.js diff --git a/test/error-runtime/error-runtime-launch-browser/trigger-error.js b/test/error_runtime/trigger_error.js similarity index 100% rename from test/error-runtime/error-runtime-launch-browser/trigger-error.js rename to test/error_runtime/trigger_error.js diff --git a/test/error-runtime/error-runtime-testing-node/file.spec.html b/test/error_syntax/error_syntax.html similarity index 72% rename from test/error-runtime/error-runtime-testing-node/file.spec.html rename to test/error_syntax/error_syntax.html index c44b700b22..ef4c97c506 100644 --- a/test/error-runtime/error-runtime-testing-node/file.spec.html +++ b/test/error_syntax/error_syntax.html @@ -7,6 +7,6 @@ - + diff --git a/test/error_syntax/error_syntax_testing/error_syntax.js b/test/error_syntax/error_syntax.js similarity index 100% rename from test/error_syntax/error_syntax_testing/error_syntax.js rename to test/error_syntax/error_syntax.js diff --git a/test/coverage/coverage_error_syntax/coverage_error_syntax.test.js b/test/error_syntax/error_syntax_coverage.test.js similarity index 71% rename from test/coverage/coverage_error_syntax/coverage_error_syntax.test.js rename to test/error_syntax/error_syntax_coverage.test.js index f1d9b12cbe..1c2b6536a8 100644 --- a/test/coverage/coverage_error_syntax/coverage_error_syntax.test.js +++ b/test/error_syntax/error_syntax_coverage.test.js @@ -1,15 +1,17 @@ import { assert } from "@jsenv/assert" -import { resolveDirectoryUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { executeTestPlan } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" import { EXECUTE_TEST_PLAN_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_TESTING.js" const testDirectoryUrl = resolveDirectoryUrl("./", import.meta.url) -const testDirectoryRelativeUrl = urlToRelativeUrl(testDirectoryUrl, jsenvCoreDirectoryUrl) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) -const fileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.js` +const fileRelativeUrl = `${testDirectoryRelativeUrl}error_syntax.js` const { testPlanCoverage } = await executeTestPlan({ ...EXECUTE_TEST_PLAN_TEST_PARAMS, executionLogLevel: "off", diff --git a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.test.js b/test/error_syntax/error_syntax_exploring.test.js similarity index 89% rename from test/error_syntax/error_syntax_exploring/error_syntax_exploring.test.js rename to test/error_syntax/error_syntax_exploring.test.js index 69396771c1..9dce81f1fa 100644 --- a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.test.js +++ b/test/error_syntax/error_syntax_exploring.test.js @@ -3,7 +3,6 @@ import { urlToRelativeUrl, urlToFileSystemPath, resolveUrl, - urlToBasename, } from "@jsenv/filesystem" import { startExploring } from "@jsenv/core" @@ -16,11 +15,10 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const htmlFilename = `${testDirectoryname}.html` +const htmlFilename = `error_syntax.html` const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}${htmlFilename}` -const importedFileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.js` +const importedFileRelativeUrl = `${testDirectoryRelativeUrl}error_syntax.js` const importedFileUrl = resolveUrl( importedFileRelativeUrl, jsenvCoreDirectoryUrl, @@ -42,16 +40,16 @@ const { browser, pageLogs, pageErrors, executionResult } = browser.close() const actual = { pageLogs, pageErrors, executionResult } -const expectedParsingErrorMessage = `${importedFilePath}: Unexpected token (1:17) +const expectedParsingErrorMessage = `${importedFilePath}: Unexpected token (1:11) -> 1 | const browser = ( - | ^` +> 1 | const a = ( + | ^` const expectedParsingError = { message: expectedParsingErrorMessage, messageHTML: assert.any(String), filename: importedFilePath, lineNumber: 1, - columnNumber: 17, + columnNumber: 11, } const expectedError = Object.assign( new Error(`Module file cannot be parsed. @@ -85,7 +83,7 @@ const expected = { startTime: assert.any(Number), endTime: assert.any(Number), fileExecutionResultMap: { - [`./${testDirectoryname}.js`]: { + [`./error_syntax.js`]: { status: "errored", exceptionSource: assert.any(String), }, diff --git a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.js b/test/error_syntax/error_syntax_exploring/error_syntax_exploring.js deleted file mode 100644 index 2d267e99b8..0000000000 --- a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.js +++ /dev/null @@ -1 +0,0 @@ -const browser = ( \ No newline at end of file diff --git a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.test.js b/test/error_syntax/error_syntax_launch_browser.test.js similarity index 87% rename from test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.test.js rename to test/error_syntax/error_syntax_launch_browser.test.js index 7b02cd6bf5..3eabb17745 100644 --- a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.test.js +++ b/test/error_syntax/error_syntax_launch_browser.test.js @@ -3,7 +3,6 @@ import { resolveUrl, urlToRelativeUrl, urlToFileSystemPath, - urlToBasename, } from "@jsenv/filesystem" import { launchChromium, launchFirefox, launchWebkit } from "@jsenv/core" @@ -23,12 +22,11 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const htmlFilename = `${testDirectoryname}.html` +const htmlFilename = `error_syntax.html` const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}${htmlFilename}` const compileId = COMPILE_ID_BEST -const importedFileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.js` +const importedFileRelativeUrl = `${testDirectoryRelativeUrl}error_syntax.js` const importedFileUrl = resolveUrl( importedFileRelativeUrl, jsenvCoreDirectoryUrl, @@ -90,23 +88,23 @@ await launchBrowsers( status: "errored", errorMessage: `Module file cannot be parsed. --- parsing error message --- -${importedFilePath}: Unexpected token (1:17) +${importedFilePath}: Unexpected token (1:11) -> 1 | const browser = ( - | ^ +> 1 | const a = ( + | ^ --- file --- ${importedFileRelativeUrl} --- file url --- ${compiledFileUrl}`, errorParsingErrror: { - message: `${importedFilePath}: Unexpected token (1:17) + message: `${importedFilePath}: Unexpected token (1:11) -> 1 | const browser = ( - | ^`, +> 1 | const a = ( + | ^`, messageHTML: assert.any(String), filename: importedFilePath, lineNumber: 1, - columnNumber: 17, + columnNumber: 11, }, } assert({ actual, expected }) diff --git a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.js b/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.js deleted file mode 100644 index 2d267e99b8..0000000000 --- a/test/error_syntax/error_syntax_launch_browser/error_syntax_launch_browser.js +++ /dev/null @@ -1 +0,0 @@ -const browser = ( \ No newline at end of file diff --git a/test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.test.js b/test/error_syntax/error_syntax_launch_node.test.js similarity index 88% rename from test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.test.js rename to test/error_syntax/error_syntax_launch_node.test.js index ac8d2c9aa0..e7bea8a363 100644 --- a/test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.test.js +++ b/test/error_syntax/error_syntax_launch_node.test.js @@ -3,7 +3,6 @@ import { resolveUrl, urlToRelativeUrl, urlToFileSystemPath, - urlToBasename, } from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" @@ -21,9 +20,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.js` +const filename = `error_syntax.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const fileUrl = resolveUrl(fileRelativeUrl, jsenvCoreDirectoryUrl) const filePath = urlToFileSystemPath(fileUrl) @@ -68,22 +66,22 @@ const test = async ({ canUseNativeModuleSystem } = {}) => { canUseNativeModuleSystem: false, }) const parsingError = { - message: `${filePath}: Unexpected token (1:14) + message: `${filePath}: Unexpected token (1:11) -> 1 | const node = ( - | ^`, +> 1 | const a = ( + | ^`, messageHTML: assert.any(String), filename: filePath, lineNumber: 1, - columnNumber: 14, + columnNumber: 11, } const expectedError = Object.assign( new Error(`Module file cannot be parsed. --- parsing error message --- -${filePath}: Unexpected token (1:14) +${filePath}: Unexpected token (1:11) -> 1 | const node = ( - | ^ +> 1 | const a = ( + | ^ --- file --- ${fileRelativeUrl} --- file url --- diff --git a/test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.js b/test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.js deleted file mode 100644 index 7fcb84a066..0000000000 --- a/test/error_syntax/error_syntax_launch_node/error_syntax_launch_node.js +++ /dev/null @@ -1 +0,0 @@ -const node = ( \ No newline at end of file diff --git a/test/error_syntax/error_syntax_testing/error_syntax_testing.html b/test/error_syntax/error_syntax_testing.html similarity index 100% rename from test/error_syntax/error_syntax_testing/error_syntax_testing.html rename to test/error_syntax/error_syntax_testing.html diff --git a/test/error_syntax/error_syntax_testing/error_syntax_testing.test.js b/test/error_syntax/error_syntax_testing.test.js similarity index 78% rename from test/error_syntax/error_syntax_testing/error_syntax_testing.test.js rename to test/error_syntax/error_syntax_testing.test.js index 6c4a8435cf..ec57d3844d 100644 --- a/test/error_syntax/error_syntax_testing/error_syntax_testing.test.js +++ b/test/error_syntax/error_syntax_testing.test.js @@ -1,9 +1,5 @@ import { assert } from "@jsenv/assert" -import { - resolveDirectoryUrl, - urlToRelativeUrl, - urlToBasename, -} from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { executeTestPlan, launchNode, launchChromium } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -15,9 +11,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( jsenvCoreDirectoryUrl, ) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) -const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.html` -const fileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.js` +const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}error_syntax.html` +const fileRelativeUrl = `${testDirectoryRelativeUrl}importing_error_syntax.js` const { testPlanCoverage } = await executeTestPlan({ ...EXECUTE_TEST_PLAN_TEST_PARAMS, executionLogLevel: "off", diff --git a/test/error_syntax/error_syntax_testing/error_syntax_testing.js b/test/error_syntax/error_syntax_testing/error_syntax_testing.js deleted file mode 100644 index 976cea3c28..0000000000 --- a/test/error_syntax/error_syntax_testing/error_syntax_testing.js +++ /dev/null @@ -1 +0,0 @@ -import "./error_syntax.js" diff --git a/test/error_syntax/importing_error_syntax.js b/test/error_syntax/importing_error_syntax.js new file mode 100644 index 0000000000..4ebd681976 --- /dev/null +++ b/test/error_syntax/importing_error_syntax.js @@ -0,0 +1 @@ +import "./error_syntax.js" \ No newline at end of file diff --git a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.html b/test/export_missing/export_missing.html similarity index 69% rename from test/error_syntax/error_syntax_exploring/error_syntax_exploring.html rename to test/export_missing/export_missing.html index 6ea9300b9e..451c6e25c3 100644 --- a/test/error_syntax/error_syntax_exploring/error_syntax_exploring.html +++ b/test/export_missing/export_missing.html @@ -7,6 +7,6 @@ - + diff --git a/test/export_missing/export_missing.js b/test/export_missing/export_missing.js new file mode 100644 index 0000000000..3c1c5cc4fe --- /dev/null +++ b/test/export_missing/export_missing.js @@ -0,0 +1,4 @@ +// eslint-disable-next-line import/named +import { answer } from "./file.js" + +console.log(answer) diff --git a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.test.js b/test/export_missing/export_missing_browser.test.js similarity index 59% rename from test/error-stack/error-stack-launch-browser/error-stack-launch-browser.test.js rename to test/export_missing/export_missing_browser.test.js index 48ae42632e..70d33e3373 100644 --- a/test/error-stack/error-stack-launch-browser/error-stack-launch-browser.test.js +++ b/test/export_missing/export_missing_browser.test.js @@ -1,26 +1,26 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { launchChromium, launchFirefox, launchWebkit } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" import { startCompileServer } from "@jsenv/core/src/internal/compiling/startCompileServer.js" import { launchAndExecute } from "@jsenv/core/src/internal/executing/launchAndExecute.js" +import { launchBrowsers } from "@jsenv/core/test/launchBrowsers.js" import { START_COMPILE_SERVER_TEST_PARAMS, EXECUTION_TEST_PARAMS, LAUNCH_TEST_PARAMS, } from "@jsenv/core/test/TEST_PARAMS_LAUNCH_BROWSER.js" -import { launchBrowsers } from "@jsenv/core/test/launchBrowsers.js" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveDirectoryUrl("./", import.meta.url) const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryBasename = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` -const filename = `${testDirectoryBasename}.html` -const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` +const htmlFilename = `export_missing.html` +const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}${htmlFilename}` + const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ ...START_COMPILE_SERVER_TEST_PARAMS, @@ -29,7 +29,7 @@ const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await launchBrowsers( [ - // ensure multiline + // comment force multiline launchChromium, launchFirefox, launchWebkit, @@ -37,40 +37,53 @@ await launchBrowsers( async (launchBrowser) => { const result = await launchAndExecute({ ...EXECUTION_TEST_PARAMS, - // sets launchAndExecuteLogLevel to off to avoid seeing an expected error in logs launchAndExecuteLogLevel: "off", - // stopAfterExecute: false, launch: (options) => launchBrowser({ ...LAUNCH_TEST_PARAMS, ...options, outDirectoryRelativeUrl, compileServerOrigin, - // headless: false, }), executeParams: { - fileRelativeUrl, + fileRelativeUrl: htmlFileRelativeUrl, }, captureConsole: true, - mirrorConsole: true, + // launchParams: { + // headless: false, + // }, + // stopAfterExecute: false, }) - const stack = result.error.stack - if (launchBrowser === launchChromium) { - const expected = `Error: error - at triggerError (${testDirectoryUrl}trigger-error.js:2:9) - at ${testDirectoryUrl}${testDirectoryBasename}.js:3:1` - const actual = stack.slice(0, expected.length) - assert({ actual, expected }) - } else if (launchBrowser === launchFirefox) { - const expected = `Error: error` - const actual = stack.slice(0, expected.length) - assert({ actual, expected }) - } else { - const actual = typeof stack - const expected = `string` + const actual = { + status: result.status, + errorMessage: result.error.message, + } + const expected = { + status: "errored", + errorMessage: `The requested module './file.js' does not provide an export named 'answer'`, + } assert({ actual, expected }) + return + } + + const actual = { + status: result.status, + consoleCalls: result.consoleCalls, + } + const expected = { + status: "completed", + consoleCalls: [ + { + type: "log", + text: + process.platform === "win32" + ? actual.consoleCalls[0].text + : `undefined\n`, + }, + ], } + assert({ actual, expected }) }, ) diff --git a/test/export_missing/export_missing_build_esmodule.test.js b/test/export_missing/export_missing_build_esmodule.test.js new file mode 100644 index 0000000000..db02049af7 --- /dev/null +++ b/test/export_missing/export_missing_build_esmodule.test.js @@ -0,0 +1,41 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + +import { buildProject } from "@jsenv/core" +import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" +import { GENERATE_ESMODULE_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_ESMODULE.js" + +const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` +const mainFilename = `export_missing.js` +const fileRelativeUrl = `${testDirectoryRelativeUrl}${mainFilename}` +const entryPointMap = { + [`./${fileRelativeUrl}`]: "./main.js", +} +const importerFileUrl = resolveUrl(mainFilename, testDirectoryUrl) +const importedFileUrl = resolveUrl("file.js", testDirectoryUrl) + +try { + await buildProject({ + ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, + jsenvDirectoryRelativeUrl, + buildDirectoryRelativeUrl, + entryPointMap, + }) + throw new Error("should throw") +} catch (e) { + const actual = e.message + const expected = `'answer' is not exported by ${importedFileUrl}, imported by ${importerFileUrl} +--- frame --- +1: // eslint-disable-next-line import/named +2: import { answer } from "./file.js"; + ^ +3: console.log(answer); +4: //# sourceMappingURL=export_missing.js.map` + assert({ actual, expected }) +} diff --git a/test/export_missing/export_missing_cjs/export_missing_cjs_build_esmodule.test.js b/test/export_missing/export_missing_cjs/export_missing_cjs_build_esmodule.test.js new file mode 100644 index 0000000000..1ed700c5e8 --- /dev/null +++ b/test/export_missing/export_missing_cjs/export_missing_cjs_build_esmodule.test.js @@ -0,0 +1,50 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + +import { buildProject } from "@jsenv/core" +import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" +import { GENERATE_ESMODULE_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_ESMODULE.js" + +const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` +const mainFilename = `file_importing_commonjs.js` +const fileRelativeUrl = `${testDirectoryRelativeUrl}${mainFilename}` +const entryPointMap = { + [`./${fileRelativeUrl}`]: "./main.js", +} +const importerFileUrl = resolveUrl(mainFilename, testDirectoryUrl) +const importedFileUrl = resolveUrl( + "file_written_in_commonjs.js", + testDirectoryUrl, +) + +try { + await buildProject({ + ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, + jsConcatenation: false, + jsenvDirectoryRelativeUrl, + buildDirectoryRelativeUrl, + entryPointMap, + }) + throw new Error("should throw") +} catch (e) { + const actual = e.message + const expected = `'answer' is not exported by ${importedFileUrl}, imported by ${importerFileUrl} +--- frame --- +1: import { answer } from "./file_written_in_commonjs.js"; + ^ +2: console.log(answer); +3: //# sourceMappingURL=file_importing_commonjs.js.map +--- suggestion --- +The file seems written in commonjs, you should use "customCompiler" to convert it to js module +{ + "./test/export_missing/export_missing_cjs/file_written_in_commonjs.js": commonJsToJavaScriptModule +} +As documented in https://github.com/jsenv/jsenv-core/blob/master/docs/shared-parameters.md#customcompilers` + assert({ actual, expected }) +} diff --git a/test/export_missing/export_missing_cjs/file.cjs b/test/export_missing/export_missing_cjs/file.cjs new file mode 100644 index 0000000000..3151feea23 --- /dev/null +++ b/test/export_missing/export_missing_cjs/file.cjs @@ -0,0 +1 @@ +exports.answer = 42 diff --git a/test/export_missing/export_missing_cjs/file_importing_commonjs.js b/test/export_missing/export_missing_cjs/file_importing_commonjs.js new file mode 100644 index 0000000000..d323b7490a --- /dev/null +++ b/test/export_missing/export_missing_cjs/file_importing_commonjs.js @@ -0,0 +1,3 @@ +import { answer } from "./file_written_in_commonjs.js" + +console.log(answer) diff --git a/test/export_missing/export_missing_cjs/file_written_in_commonjs.js b/test/export_missing/export_missing_cjs/file_written_in_commonjs.js new file mode 100644 index 0000000000..e0c3faa206 --- /dev/null +++ b/test/export_missing/export_missing_cjs/file_written_in_commonjs.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line no-undef +module.exports = require("./file.cjs") diff --git a/test/error-stack/error-stack-launch-node/error-stack-launch-node.test.js b/test/export_missing/export_missing_launch_node.test.js similarity index 62% rename from test/error-stack/error-stack-launch-node/error-stack-launch-node.test.js rename to test/export_missing/export_missing_launch_node.test.js index d756eb4aef..46c7bda81d 100644 --- a/test/error-stack/error-stack-launch-node/error-stack-launch-node.test.js +++ b/test/export_missing/export_missing_launch_node.test.js @@ -1,5 +1,9 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { + resolveUrl, + resolveDirectoryUrl, + urlToRelativeUrl, +} from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -11,24 +15,23 @@ import { LAUNCH_TEST_PARAMS, } from "@jsenv/core/test/TEST_PARAMS_LAUNCH_NODE.js" -const testDirectoryUrl = resolveUrl("./", import.meta.url) -const testDirectoryRelativePath = urlToRelativeUrl( +const testDirectoryUrl = resolveDirectoryUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativePath) -const jsenvDirectoryRelativeUrl = `${testDirectoryRelativePath}.jsenv/` -const filename = `${testDirectoryname}.js` -const fileRelativeUrl = `${testDirectoryRelativePath}${filename}` +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const mainFilename = `export_missing.js` +const fileRelativeUrl = `${testDirectoryRelativeUrl}${mainFilename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ ...START_COMPILE_SERVER_TEST_PARAMS, jsenvDirectoryRelativeUrl, }) +const importerFileUrl = resolveUrl(mainFilename, testDirectoryUrl) const result = await launchAndExecute({ ...LAUNCH_AND_EXECUTE_TEST_PARAMS, - // sets launchAndExecuteLogLevel to off to avoid seeing an expected error in logs launchAndExecuteLogLevel: "off", launch: (options) => launchNode({ @@ -40,12 +43,11 @@ const result = await launchAndExecute({ executeParams: { fileRelativeUrl, }, - mirrorConsole: true, }) const stack = result.error.stack - -const expected = `Error: error - at triggerError (${testDirectoryUrl}trigger-error.js:2:9) - at ${testDirectoryUrl}${testDirectoryname}.js:3:1` +const expected = `${importerFileUrl}:2 +import { answer } from "./file.js" + ^^^^^^ +SyntaxError: The requested module './file.js' does not provide an export named 'answer'` const actual = stack.slice(0, expected.length) assert({ actual, expected }) diff --git a/test/dynamic-import/dynamic-import-build-commonjs/answer.js b/test/export_missing/file.js similarity index 100% rename from test/dynamic-import/dynamic-import-build-commonjs/answer.js rename to test/export_missing/file.js diff --git a/test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.js b/test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.js deleted file mode 100644 index ca72bb1885..0000000000 --- a/test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.js +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line import/no-unresolved -import "./foo.js" diff --git a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.html b/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.html deleted file mode 100644 index f4021e8856..0000000000 --- a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Title - - - - - - - - diff --git a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.js b/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.js deleted file mode 100644 index ca72bb1885..0000000000 --- a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.js +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line import/no-unresolved -import "./foo.js" diff --git a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.html b/test/import_not_found/import_not_found.html similarity index 69% rename from test/error-runtime/error-runtime-exploring/error-runtime-exploring.html rename to test/import_not_found/import_not_found.html index 88a885a878..e7dc99294e 100644 --- a/test/error-runtime/error-runtime-exploring/error-runtime-exploring.html +++ b/test/import_not_found/import_not_found.html @@ -7,6 +7,6 @@ - + diff --git a/test/file-not-found/js-import-not-found-launch-node/js-import-not-found-launch-node.js b/test/import_not_found/import_not_found.js similarity index 100% rename from test/file-not-found/js-import-not-found-launch-node/js-import-not-found-launch-node.js rename to test/import_not_found/import_not_found.js diff --git a/test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.test.js b/test/import_not_found/import_not_found_build_esmodule.test.js similarity index 90% rename from test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.test.js rename to test/import_not_found/import_not_found_build_esmodule.test.js index b98fcd1a29..54652c57c4 100644 --- a/test/file-not-found/js_import_not_found_build_esmodule/js_import_not_found_build_esmodule.test.js +++ b/test/import_not_found/import_not_found_build_esmodule.test.js @@ -3,7 +3,6 @@ import { resolveUrl, urlToRelativeUrl, urlToFileSystemPath, - urlToBasename, } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" @@ -15,10 +14,9 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` -const mainFilename = `${testDirectoryname}.js` +const mainFilename = `import_not_found.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${mainFilename}` const entryPointMap = { [`./${fileRelativeUrl}`]: "./main.js", diff --git a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.test.js b/test/import_not_found/import_not_found_launch_browser.test.js similarity index 93% rename from test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.test.js rename to test/import_not_found/import_not_found_launch_browser.test.js index 9cf15c81cb..176812d9d7 100644 --- a/test/file-not-found/js_import_not_found_launch_browser/js_import_not_found_launch_browser.test.js +++ b/test/import_not_found/import_not_found_launch_browser.test.js @@ -3,7 +3,6 @@ import { resolveUrl, resolveDirectoryUrl, urlToRelativeUrl, - urlToBasename, } from "@jsenv/filesystem" import { launchChromium, launchFirefox, launchWebkit } from "@jsenv/core" @@ -23,11 +22,10 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv` -const htmlFilename = `${testDirectoryname}.html` +const htmlFilename = `import_not_found.html` const htmlFileRelativeUrl = `${testDirectoryRelativeUrl}${htmlFilename}` -const importerFileRelativeUrl = `${testDirectoryRelativeUrl}${testDirectoryname}.js` +const importerFileRelativeUrl = `${testDirectoryRelativeUrl}import_not_found.js` const compileId = COMPILE_ID_BEST const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ diff --git a/test/file-not-found/js-import-not-found-launch-node/js-import-not-found-launch-node.test.js b/test/import_not_found/import_not_found_launch_node.test.js similarity index 93% rename from test/file-not-found/js-import-not-found-launch-node/js-import-not-found-launch-node.test.js rename to test/import_not_found/import_not_found_launch_node.test.js index 0a30e8b8a9..b1d35556dd 100644 --- a/test/file-not-found/js-import-not-found-launch-node/js-import-not-found-launch-node.test.js +++ b/test/import_not_found/import_not_found_launch_node.test.js @@ -4,7 +4,6 @@ import { resolveDirectoryUrl, urlToRelativeUrl, urlToFileSystemPath, - urlToBasename, } from "@jsenv/filesystem" import { launchNode } from "@jsenv/core" @@ -22,9 +21,8 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const filename = `${testDirectoryname}.js` +const filename = `import_not_found.js` const fileRelativeUrl = `${testDirectoryRelativeUrl}${filename}` const { origin: compileServerOrigin, outDirectoryRelativeUrl } = await startCompileServer({ diff --git a/test/known_package_import/importing_cjs_a/cjs_a.cjs b/test/known_package_import/importing_cjs_a/cjs_a.cjs new file mode 100644 index 0000000000..3151feea23 --- /dev/null +++ b/test/known_package_import/importing_cjs_a/cjs_a.cjs @@ -0,0 +1 @@ +exports.answer = 42 diff --git a/test/known_package_import/importing_cjs_a/importing_cjs_a.test.js b/test/known_package_import/importing_cjs_a/importing_cjs_a.test.js new file mode 100644 index 0000000000..c55c353157 --- /dev/null +++ b/test/known_package_import/importing_cjs_a/importing_cjs_a.test.js @@ -0,0 +1,42 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + +import { buildProject, commonJsToJavaScriptModule } from "@jsenv/core" +import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" +import { GENERATE_ESMODULE_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_ESMODULE.js" +import { nodeImportEsModuleBuild } from "@jsenv/core/test/nodeImportEsModuleBuild.js" + +const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` +const entryPointMap = { + [`./${testDirectoryRelativeUrl}main.js`]: "./main.js", +} +await buildProject({ + ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, + // logLevel: "debug", + jsenvDirectoryRelativeUrl, + buildDirectoryRelativeUrl, + entryPointMap, + customCompilers: { + "**/*.cjs": commonJsToJavaScriptModule, + }, +}) +const { namespace } = await nodeImportEsModuleBuild({ + projectDirectoryUrl: jsenvCoreDirectoryUrl, + testDirectoryRelativeUrl, + jsFileRelativeUrl: "dist/esmodule/main.js", +}) + +const actual = namespace +const expected = { + namedExports: { + answer: 42, + default: { answer: 42 }, // it's duplicated on default, that's fine + }, +} +assert({ actual, expected }) diff --git a/test/known_package_import/importing_cjs_a/main.js b/test/known_package_import/importing_cjs_a/main.js new file mode 100644 index 0000000000..dc8f5f3ff8 --- /dev/null +++ b/test/known_package_import/importing_cjs_a/main.js @@ -0,0 +1 @@ +export * as namedExports from "./cjs_a.cjs" diff --git a/test/known_package_import/importing_cjs_b/cjs_b.cjs b/test/known_package_import/importing_cjs_b/cjs_b.cjs new file mode 100644 index 0000000000..12cd8ec36a --- /dev/null +++ b/test/known_package_import/importing_cjs_b/cjs_b.cjs @@ -0,0 +1 @@ +module.exports = require("./file.cjs") diff --git a/test/known_package_import/importing_cjs_b/file.cjs b/test/known_package_import/importing_cjs_b/file.cjs new file mode 100644 index 0000000000..26a94e9047 --- /dev/null +++ b/test/known_package_import/importing_cjs_b/file.cjs @@ -0,0 +1,5 @@ +Object.defineProperty(exports, "__esModule", { + value: true, +}) + +exports.answer = 42 diff --git a/test/known_package_import/importing_cjs_b/importing_cjs_b.test.js b/test/known_package_import/importing_cjs_b/importing_cjs_b.test.js new file mode 100644 index 0000000000..3b00bea333 --- /dev/null +++ b/test/known_package_import/importing_cjs_b/importing_cjs_b.test.js @@ -0,0 +1,42 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + +import { buildProject, commonJsToJavaScriptModule } from "@jsenv/core" +import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" +import { GENERATE_ESMODULE_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_ESMODULE.js" +import { nodeImportEsModuleBuild } from "@jsenv/core/test/nodeImportEsModuleBuild.js" + +const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` +const entryPointMap = { + [`./${testDirectoryRelativeUrl}main.js`]: "./main.js", +} +await buildProject({ + ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, + // logLevel: "debug", + jsenvDirectoryRelativeUrl, + buildDirectoryRelativeUrl, + entryPointMap, + customCompilers: { + "**/*.cjs": commonJsToJavaScriptModule, + }, +}) +const { namespace } = await nodeImportEsModuleBuild({ + projectDirectoryUrl: jsenvCoreDirectoryUrl, + testDirectoryRelativeUrl, + jsFileRelativeUrl: "dist/esmodule/main.js", +}) + +const actual = namespace +const expected = { + namedExports: { + // argl, it should be { answer: 42 } not inside behind default export :( + default: { answer: 42 }, + }, +} +assert({ actual, expected }) diff --git a/test/known_package_import/importing_cjs_b/main.js b/test/known_package_import/importing_cjs_b/main.js new file mode 100644 index 0000000000..82291127c3 --- /dev/null +++ b/test/known_package_import/importing_cjs_b/main.js @@ -0,0 +1 @@ +export * as namedExports from "./cjs_b.cjs" diff --git a/test/known_package_import/importing_react/importing_react.js b/test/known_package_import/importing_react/importing_react.js index cf74310350..938f1d942d 100644 --- a/test/known_package_import/importing_react/importing_react.js +++ b/test/known_package_import/importing_react/importing_react.js @@ -1,3 +1,5 @@ -import React from "react" +import React, { useEffect } from "react" -export default typeof React +export const ReactDefaultExport = typeof React === "function" + +export const useEffectExport = typeof useEffect === "function" diff --git a/test/known_package_import/importing_react/importing_react_build_global.test.js b/test/known_package_import/importing_react/importing_react_build_global.test.js deleted file mode 100644 index 3a99db8542..0000000000 --- a/test/known_package_import/importing_react/importing_react_build_global.test.js +++ /dev/null @@ -1,48 +0,0 @@ -import { assert } from "@jsenv/assert" -import { resolveDirectoryUrl, urlToRelativeUrl } from "@jsenv/filesystem" - -import { buildProject, commonJsToJavaScriptModule } from "@jsenv/core" -import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" -import { - GENERATE_GLOBAL_BUILD_TEST_PARAMS, - SCRIPT_LOAD_GLOBAL_BUILD_TEST_PARAMS, -} from "@jsenv/core/test/TEST_PARAMS_BUILD_GLOBAL.js" -import { scriptLoadGlobalBuild } from "@jsenv/core/test/scriptLoadGlobalBuild.js" - -const testDirectoryUrl = resolveDirectoryUrl("./", import.meta.url) -const testDirectoryRelativeUrl = urlToRelativeUrl( - testDirectoryUrl, - jsenvCoreDirectoryUrl, -) - -const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` -const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/global/` -const mainFilename = `importing_react.html` -const entryPointMap = { - [`./${testDirectoryRelativeUrl}${mainFilename}`]: "./main.html", -} - -const { buildMappings } = await buildProject({ - ...GENERATE_GLOBAL_BUILD_TEST_PARAMS, - jsenvDirectoryRelativeUrl, - buildDirectoryRelativeUrl, - entryPointMap, - customCompilers: { - "./node_modules/react/index.js": (options) => - commonJsToJavaScriptModule({ - ...options, - processEnvNodeEnv: "dev", - }), - }, -}) -const mainJsFileBuildRelativeUrl = - buildMappings[`${testDirectoryRelativeUrl}importing_react.js`] -const { globalValue } = await scriptLoadGlobalBuild({ - ...SCRIPT_LOAD_GLOBAL_BUILD_TEST_PARAMS, - buildDirectoryRelativeUrl, - mainRelativeUrl: `./${mainJsFileBuildRelativeUrl}`, -}) - -const actual = globalValue -const expected = "object" -assert({ actual, expected }) diff --git a/test/known_package_import/importing_react/importing_react_build_systemjs.test.js b/test/known_package_import/importing_react/importing_react_build_systemjs.test_disabled.js similarity index 97% rename from test/known_package_import/importing_react/importing_react_build_systemjs.test.js rename to test/known_package_import/importing_react/importing_react_build_systemjs.test_disabled.js index 766d2bc8c7..ec604df9c0 100644 --- a/test/known_package_import/importing_react/importing_react_build_systemjs.test.js +++ b/test/known_package_import/importing_react/importing_react_build_systemjs.test_disabled.js @@ -49,6 +49,7 @@ const { namespace } = await browserImportSystemJsBuild({ const actual = namespace const expected = { - default: "object", + ReactDefaultExport: true, + useEffectExport: true, } assert({ actual, expected }) diff --git a/test/known_package_import/importing_react/importing_react_execute_chromium.test.js b/test/known_package_import/importing_react/importing_react_execute_chromium.test_disabled.js similarity index 94% rename from test/known_package_import/importing_react/importing_react_execute_chromium.test.js rename to test/known_package_import/importing_react/importing_react_execute_chromium.test_disabled.js index 9280a078ef..8bb998dd2a 100644 --- a/test/known_package_import/importing_react/importing_react_execute_chromium.test.js +++ b/test/known_package_import/importing_react/importing_react_execute_chromium.test_disabled.js @@ -37,7 +37,8 @@ const expected = { "./importing_react.js": { status: "completed", namespace: { - default: "object", + ReactDefaultExport: true, + useEffectExport: true, }, }, }, diff --git a/test/known_package_import/importing_umd/file.js b/test/known_package_import/importing_umd/file.js new file mode 100644 index 0000000000..382e822aa9 --- /dev/null +++ b/test/known_package_import/importing_umd/file.js @@ -0,0 +1 @@ +export * as namedExports from "./file_umd.js" diff --git a/test/known_package_import/importing_umd/file_umd.js b/test/known_package_import/importing_umd/file_umd.js new file mode 100644 index 0000000000..1c6dc474b4 --- /dev/null +++ b/test/known_package_import/importing_umd/file_umd.js @@ -0,0 +1,14 @@ +/* eslint-disable */ +;(function (global, factory) { + typeof exports === "object" && typeof module !== "undefined" + ? factory(exports) + : typeof define === "function" && define.amd + ? define(["exports"], factory) + : ((global = global || self), factory((global.Carpenter = {}))) +})(this, function (exports) { + "use strict" + + exports.answer = 42 + + Object.defineProperty(exports, "__esModule", { value: true }) +}) diff --git a/test/known_package_import/importing_umd/importing_umd.test.js b/test/known_package_import/importing_umd/importing_umd.test.js new file mode 100644 index 0000000000..13f72871bc --- /dev/null +++ b/test/known_package_import/importing_umd/importing_umd.test.js @@ -0,0 +1,44 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" + +import { buildProject, commonJsToJavaScriptModule } from "@jsenv/core" +import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" +import { GENERATE_ESMODULE_BUILD_TEST_PARAMS } from "@jsenv/core/test/TEST_PARAMS_BUILD_ESMODULE.js" +import { nodeImportEsModuleBuild } from "@jsenv/core/test/nodeImportEsModuleBuild.js" + +const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryRelativeUrl = urlToRelativeUrl( + testDirectoryUrl, + jsenvCoreDirectoryUrl, +) +const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` +const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/esmodule/` +const entryPointMap = { + [`./${testDirectoryRelativeUrl}file.js`]: "./file.js", +} +await buildProject({ + ...GENERATE_ESMODULE_BUILD_TEST_PARAMS, + // logLevel: "debug", + jsenvDirectoryRelativeUrl, + buildDirectoryRelativeUrl, + entryPointMap, + customCompilers: { + "**/file_umd.js": commonJsToJavaScriptModule, + }, +}) +const { namespace } = await nodeImportEsModuleBuild({ + projectDirectoryUrl: jsenvCoreDirectoryUrl, + testDirectoryRelativeUrl, + jsFileRelativeUrl: "dist/esmodule/file.js", +}) + +const actual = namespace +const expected = { + namedExports: { + // argl, it should be { answer: 42 } not inside behind default export :( + default: { + answer: 42, + }, + }, +} +assert({ actual, expected }) diff --git a/test/build_top_level_await_systemjs/build_top_level_await_systemjs.test.js b/test/top_level_await/top_level_await_build_systemjs.test.js similarity index 65% rename from test/build_top_level_await_systemjs/build_top_level_await_systemjs.test.js rename to test/top_level_await/top_level_await_build_systemjs.test.js index 99e4b80683..abc13f8794 100644 --- a/test/build_top_level_await_systemjs/build_top_level_await_systemjs.test.js +++ b/test/top_level_await/top_level_await_build_systemjs.test.js @@ -1,5 +1,5 @@ import { assert } from "@jsenv/assert" -import { resolveUrl, urlToRelativeUrl, urlToBasename } from "@jsenv/filesystem" +import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem" import { buildProject } from "@jsenv/core" import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js" @@ -14,28 +14,28 @@ const testDirectoryRelativeUrl = urlToRelativeUrl( testDirectoryUrl, jsenvCoreDirectoryUrl, ) -const testDirectoryname = urlToBasename(testDirectoryRelativeUrl) const jsenvDirectoryRelativeUrl = `${testDirectoryRelativeUrl}.jsenv/` const buildDirectoryRelativeUrl = `${testDirectoryRelativeUrl}dist/systemjs/` const entryPointMap = { - [`./${testDirectoryRelativeUrl}${testDirectoryname}.js`]: "./main.js", + [`./${testDirectoryRelativeUrl}top_level_await.html`]: "./main.html", } - -await buildProject({ +const { buildMappings } = await buildProject({ ...GENERATE_SYSTEMJS_BUILD_TEST_PARAMS, jsenvDirectoryRelativeUrl, buildDirectoryRelativeUrl, entryPointMap, // logLevel: "debug", }) +const mainJsBuildRelativeUrl = + buildMappings[`${testDirectoryRelativeUrl}top_level_await.js`] +const { namespace } = await browserImportSystemJsBuild({ + ...IMPORT_SYSTEM_JS_BUILD_TEST_PARAMS, + testDirectoryRelativeUrl, + mainRelativeUrl: `./${mainJsBuildRelativeUrl}`, +}) { - const { namespace } = await browserImportSystemJsBuild({ - ...IMPORT_SYSTEM_JS_BUILD_TEST_PARAMS, - testDirectoryRelativeUrl, - htmlFileRelativeUrl: "./index.html", - }) const actual = namespace - const expected = { value: 42 } + const expected = { default: 42 } assert({ actual, expected }) }