diff options
author | haturau <135221985+haturatu@users.noreply.github.com> | 2024-11-20 01:20:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 01:20:47 +0900 |
commit | 85719a67e59c7aa45bead26e4942d7df8b1b42d4 (patch) | |
tree | face0aecaac53e93ce2f23b53c48859bcf1a36ec /tests/specs/run/import_common_js | |
parent | 67697bc2e4a62a9670699fd18ad0dd8efc5bd955 (diff) | |
parent | 186b52731c6bb326c4d32905c5e732d082e83465 (diff) |
Merge branch 'denoland:main' into main
Diffstat (limited to 'tests/specs/run/import_common_js')
-rw-r--r-- | tests/specs/run/import_common_js/__test__.jsonc | 23 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/a.js | 7 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/exports_error.out | 8 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/index.cjs | 2 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/index.out | 2 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/main.out | 2 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/module_error.out | 8 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/node_modules/foo/index.mjs | 1 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/require_error.js | 2 | ||||
-rw-r--r-- | tests/specs/run/import_common_js/require_error.out | 11 |
10 files changed, 43 insertions, 23 deletions
diff --git a/tests/specs/run/import_common_js/__test__.jsonc b/tests/specs/run/import_common_js/__test__.jsonc index 950c7f68c..0602a09ba 100644 --- a/tests/specs/run/import_common_js/__test__.jsonc +++ b/tests/specs/run/import_common_js/__test__.jsonc @@ -1,16 +1,27 @@ { - "steps": [ - { "args": "run -R index.cjs", "output": "index.out" }, - { "args": "run -R main.ts", "output": "main.out" }, - { + "tests": { + "cjs_entrypoint": { + "args": "run -R index.cjs", + "output": "index.out" + }, + "esm_entrypoint": { + "args": "run -R main.ts", + "output": "main.out" + }, + "module_error": { "args": "run module_error.js", "output": "module_error.out", "exitCode": 1 }, - { + "exports_error": { "args": "run exports_error.js", "output": "exports_error.out", "exitCode": 1 + }, + "require_error": { + "args": "run require_error.js", + "output": "require_error.out", + "exitCode": 1 } - ] + } } diff --git a/tests/specs/run/import_common_js/a.js b/tests/specs/run/import_common_js/a.js deleted file mode 100644 index c465ab588..000000000 --- a/tests/specs/run/import_common_js/a.js +++ /dev/null @@ -1,7 +0,0 @@ -function foobar() { - console.log("foobar"); -} - -module.exports = { - foobar, -}; diff --git a/tests/specs/run/import_common_js/exports_error.out b/tests/specs/run/import_common_js/exports_error.out index 41eda2457..baa44682b 100644 --- a/tests/specs/run/import_common_js/exports_error.out +++ b/tests/specs/run/import_common_js/exports_error.out @@ -3,5 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); ^ at [WILDCARD]exports_error.js:1:23 - info: Deno does not support CommonJS modules without `.cjs` extension. - hint: Rewrite this module to ESM or change the file extension to `.cjs`. + info: Deno supports CommonJS modules in .cjs files, or when the closest + package.json has a "type": "commonjs" option. + hint: Rewrite this module to ESM, + or change the file extension to .cjs, + or add package.json next to the file with "type": "commonjs" option. + docs: https://docs.deno.com/go/commonjs diff --git a/tests/specs/run/import_common_js/index.cjs b/tests/specs/run/import_common_js/index.cjs index 18caf81e9..0026e237d 100644 --- a/tests/specs/run/import_common_js/index.cjs +++ b/tests/specs/run/import_common_js/index.cjs @@ -1,9 +1,7 @@ const process = require("process"); -const a = require("./a"); console.log(process.cwd()); module.exports = { cwd: process.cwd, - foobar: a.foobar, }; diff --git a/tests/specs/run/import_common_js/index.out b/tests/specs/run/import_common_js/index.out index 3650631b7..6a734b994 100644 --- a/tests/specs/run/import_common_js/index.out +++ b/tests/specs/run/import_common_js/index.out @@ -1 +1 @@ -[WILDCARD]import_common_js +[WILDLINE]import_common_js diff --git a/tests/specs/run/import_common_js/main.out b/tests/specs/run/import_common_js/main.out index 03301b362..9df312975 100644 --- a/tests/specs/run/import_common_js/main.out +++ b/tests/specs/run/import_common_js/main.out @@ -1,5 +1,3 @@ hello from foo node module [WILDCARD]import_common_js cjsModule.cwd() [WILDCARD]import_common_js -foobar -cjsModule.foobar() undefined diff --git a/tests/specs/run/import_common_js/module_error.out b/tests/specs/run/import_common_js/module_error.out index 53a908d29..957b19cb1 100644 --- a/tests/specs/run/import_common_js/module_error.out +++ b/tests/specs/run/import_common_js/module_error.out @@ -3,5 +3,9 @@ module.exports = { ^ at [WILDCARD]module_error.js:1:1 - info: Deno does not support CommonJS modules without `.cjs` extension. - hint: Rewrite this module to ESM or change the file extension to `.cjs`. + info: Deno supports CommonJS modules in .cjs files, or when the closest + package.json has a "type": "commonjs" option. + hint: Rewrite this module to ESM, + or change the file extension to .cjs, + or add package.json next to the file with "type": "commonjs" option. + docs: https://docs.deno.com/go/commonjs diff --git a/tests/specs/run/import_common_js/node_modules/foo/index.mjs b/tests/specs/run/import_common_js/node_modules/foo/index.mjs index cc93554c7..7a11d39ae 100644 --- a/tests/specs/run/import_common_js/node_modules/foo/index.mjs +++ b/tests/specs/run/import_common_js/node_modules/foo/index.mjs @@ -10,5 +10,4 @@ export default async function () { const cjsModule = await import(url.pathToFileURL(cjsFileToImport)); console.log("cjsModule.cwd()", cjsModule.cwd()); - console.log("cjsModule.foobar()", cjsModule.foobar()); } diff --git a/tests/specs/run/import_common_js/require_error.js b/tests/specs/run/import_common_js/require_error.js new file mode 100644 index 000000000..956768933 --- /dev/null +++ b/tests/specs/run/import_common_js/require_error.js @@ -0,0 +1,2 @@ +const process = require("process"); +const a = require("./a"); diff --git a/tests/specs/run/import_common_js/require_error.out b/tests/specs/run/import_common_js/require_error.out new file mode 100644 index 000000000..e13db85e8 --- /dev/null +++ b/tests/specs/run/import_common_js/require_error.out @@ -0,0 +1,11 @@ +error: Uncaught (in promise) ReferenceError: require is not defined +const process = require("process"); + ^ + at [WILDCARD]require_error.js:1:17 + + info: Deno supports CommonJS modules in .cjs files, or when the closest + package.json has a "type": "commonjs" option. + hint: Rewrite this module to ESM, + or change the file extension to .cjs, + or add package.json next to the file with "type": "commonjs" option. + docs: https://docs.deno.com/go/commonjs |