-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve assertion validation and errors, add tests
- Loading branch information
1 parent
bd7c391
commit 10ba639
Showing
8 changed files
with
166 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Flags: --experimental-json-modules | ||
'use strict'; | ||
const common = require('../common'); | ||
const { rejects, strictEqual } = require('assert'); | ||
|
||
const jsModuleDataUrl = 'data:text/javascript,export{}'; | ||
const jsonModuleDataUrl = 'data:application/json,""'; | ||
|
||
async function test() { | ||
await rejects( | ||
// This rejects because of the unsupported MIME type, not because of the unsupported assertion | ||
import(`data:text/css,`, { assert: { type: 'css' } }), | ||
{ code: 'ERR_INVALID_MODULE_SPECIFIER' } | ||
) | ||
|
||
await rejects( | ||
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import(jsModuleDataUrl, { assert: { type: 'json' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import('data:text/javascript,', { assert: { type: 'unsupported' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: {} }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: { foo: 'bar' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: { type: 'unsupported' }}), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } | ||
); | ||
} | ||
|
||
test().then(common.mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Flags: --experimental-json-modules | ||
import '../common/index.mjs'; | ||
import { rejects } from 'assert'; | ||
|
||
const jsModuleDataUrl = 'data:text/javascript,export{}'; | ||
const jsonModuleDataUrl = 'data:application/json,""'; | ||
|
||
await rejects( | ||
// This rejects because of the unsupported MIME type, not because of the unsupported assertion | ||
import(`data:text/css,`, { assert: { type: 'css' } }), | ||
{ code: 'ERR_INVALID_MODULE_SPECIFIER' } | ||
) | ||
|
||
await rejects( | ||
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import(jsModuleDataUrl, { assert: { type: 'json' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import(import.meta.url, { assert: { type: 'unsupported' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: {} }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: { foo: 'bar' } }), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | ||
); | ||
|
||
await rejects( | ||
import(jsonModuleDataUrl, { assert: { type: 'unsupported' }}), | ||
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |