summaryrefslogtreecommitdiff
path: root/test/message
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2021-08-28 01:47:49 +0200
committerDanielle Adams <adamzdanielle@gmail.com>2022-01-31 21:45:46 -0500
commit1b8169a8423c17234625ff2c3c0a40d6ee96a050 (patch)
treeb69fdff8774399fb7626dd42d31e3c9a6a35335a /test/message
parent036650e0463da4e345357e71ae7a4695b5049cda (diff)
downloadnode-new-1b8169a8423c17234625ff2c3c0a40d6ee96a050.tar.gz
esm: add support for JSON import assertion
Remove V8 flag for import assertions, enabling support for the syntax; require the import assertion syntax for imports of JSON. Support import assertions in user loaders. Use both resolved module URL and import assertion type as the key for caching modules. Co-authored-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: https://github.com/nodejs/node/pull/40250 Backport-PR-URL: https://github.com/nodejs/node/pull/41776 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Diffstat (limited to 'test/message')
-rw-r--r--test/message/esm_display_syntax_error_import_json_named_export.mjs4
-rw-r--r--test/message/esm_display_syntax_error_import_json_named_export.out10
-rw-r--r--test/message/esm_import_assertion_failed.mjs2
-rw-r--r--test/message/esm_import_assertion_failed.out17
-rw-r--r--test/message/esm_import_assertion_missing.mjs3
-rw-r--r--test/message/esm_import_assertion_missing.out17
-rw-r--r--test/message/esm_import_assertion_unsupported.mjs2
-rw-r--r--test/message/esm_import_assertion_unsupported.out17
8 files changed, 72 insertions, 0 deletions
diff --git a/test/message/esm_display_syntax_error_import_json_named_export.mjs b/test/message/esm_display_syntax_error_import_json_named_export.mjs
new file mode 100644
index 0000000000..3b7c721daf
--- /dev/null
+++ b/test/message/esm_display_syntax_error_import_json_named_export.mjs
@@ -0,0 +1,4 @@
+// Flags: --experimental-json-modules
+/* eslint-disable no-unused-vars */
+import '../common/index.mjs';
+import { ofLife } from '../fixtures/experimental.json' assert { type: 'json' };
diff --git a/test/message/esm_display_syntax_error_import_json_named_export.out b/test/message/esm_display_syntax_error_import_json_named_export.out
new file mode 100644
index 0000000000..249f27f7e5
--- /dev/null
+++ b/test/message/esm_display_syntax_error_import_json_named_export.out
@@ -0,0 +1,10 @@
+file:///*/test/message/esm_display_syntax_error_import_json_named_export.mjs:*
+import { ofLife } from '../fixtures/experimental.json' assert { type: 'json' };
+ ^^^^^^
+SyntaxError: The requested module '../fixtures/experimental.json' does not provide an export named 'ofLife'
+ at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*)
+ at async ModuleJob.run (node:internal/modules/esm/module_job:*:*)
+ at async Promise.all (index 0)
+ at async ESMLoader.import (node:internal/modules/esm/loader:*:*)
+ at async loadESM (node:internal/process/esm_loader:*:*)
+ at async handleMainPromise (node:internal/modules/run_main:*:*)
diff --git a/test/message/esm_import_assertion_failed.mjs b/test/message/esm_import_assertion_failed.mjs
new file mode 100644
index 0000000000..30ea65c3e3
--- /dev/null
+++ b/test/message/esm_import_assertion_failed.mjs
@@ -0,0 +1,2 @@
+import '../common/index.mjs';
+import 'data:text/javascript,export{}' assert {type:'json'};
diff --git a/test/message/esm_import_assertion_failed.out b/test/message/esm_import_assertion_failed.out
new file mode 100644
index 0000000000..545f8cc062
--- /dev/null
+++ b/test/message/esm_import_assertion_failed.out
@@ -0,0 +1,17 @@
+node:internal/errors:*
+ ErrorCaptureStackTrace(err);
+ ^
+
+TypeError [ERR_IMPORT_ASSERTION_TYPE_FAILED]: Module "data:text/javascript,export{}" is not of type "json"
+ at new NodeError (node:internal/errors:*:*)
+ at handleInvalidType (node:internal/modules/esm/assert:*:*)
+ at validateAssertions (node:internal/modules/esm/assert:*:*)
+ at defaultLoad (node:internal/modules/esm/load:*:*)
+ at ESMLoader.load (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*)
+ at new ModuleJob (node:internal/modules/esm/module_job:*:*)
+ at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*)
+ at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:*:*) {
+ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED'
+}
diff --git a/test/message/esm_import_assertion_missing.mjs b/test/message/esm_import_assertion_missing.mjs
new file mode 100644
index 0000000000..0b402d9e7f
--- /dev/null
+++ b/test/message/esm_import_assertion_missing.mjs
@@ -0,0 +1,3 @@
+// Flags: --experimental-json-modules
+import '../common/index.mjs';
+import 'data:application/json,{}';
diff --git a/test/message/esm_import_assertion_missing.out b/test/message/esm_import_assertion_missing.out
new file mode 100644
index 0000000000..0d25d948d8
--- /dev/null
+++ b/test/message/esm_import_assertion_missing.out
@@ -0,0 +1,17 @@
+node:internal/errors:*
+ ErrorCaptureStackTrace(err);
+ ^
+
+TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "data:application/json,{}" needs an import assertion of type "json"
+ at new NodeError (node:internal/errors:*:*)
+ at validateAssertions (node:internal/modules/esm/assert:*:*)
+ at defaultLoad (node:internal/modules/esm/load:*:*)
+ at ESMLoader.load (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*)
+ at new ModuleJob (node:internal/modules/esm/module_job:*:*)
+ at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*)
+ at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:*:*)
+ at async Promise.all (index *) {
+ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING'
+}
diff --git a/test/message/esm_import_assertion_unsupported.mjs b/test/message/esm_import_assertion_unsupported.mjs
new file mode 100644
index 0000000000..86e594ce02
--- /dev/null
+++ b/test/message/esm_import_assertion_unsupported.mjs
@@ -0,0 +1,2 @@
+import '../common/index.mjs';
+import '../fixtures/empty.js' assert { type: 'unsupported' };
diff --git a/test/message/esm_import_assertion_unsupported.out b/test/message/esm_import_assertion_unsupported.out
new file mode 100644
index 0000000000..c35ba5bfe0
--- /dev/null
+++ b/test/message/esm_import_assertion_unsupported.out
@@ -0,0 +1,17 @@
+node:internal/errors:*
+ ErrorCaptureStackTrace(err);
+ ^
+
+TypeError [ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED]: Import assertion type "unsupported" is unsupported
+ at new NodeError (node:internal/errors:*:*)
+ at handleInvalidType (node:internal/modules/esm/assert:*:*)
+ at validateAssertions (node:internal/modules/esm/assert:*:*)
+ at defaultLoad (node:internal/modules/esm/load:*:*)
+ at ESMLoader.load (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*)
+ at new ModuleJob (node:internal/modules/esm/module_job:*:*)
+ at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*)
+ at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*)
+ at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:*:*) {
+ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED'
+}