1import { expectWarning } from '../common/index.mjs'; 2import { rejects } from 'assert'; 3 4const jsModuleDataUrl = 'data:text/javascript,export{}'; 5const jsonModuleDataUrl = 'data:application/json,""'; 6 7expectWarning( 8 'ExperimentalWarning', 9 'Import assertions are not a stable feature of the JavaScript language. ' + 10 'Avoid relying on their current behavior and syntax as those might change ' + 11 'in a future version of Node.js.' 12); 13 14 15await rejects( 16 // This rejects because of the unsupported MIME type, not because of the 17 // unsupported assertion. 18 import('data:text/css,', { assert: { type: 'css' } }), 19 { code: 'ERR_UNKNOWN_MODULE_FORMAT' } 20); 21 22await rejects( 23 import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`), 24 { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } 25); 26 27await rejects( 28 import(jsModuleDataUrl, { assert: { type: 'json' } }), 29 { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } 30); 31 32await rejects( 33 import(import.meta.url, { assert: { type: 'unsupported' } }), 34 { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } 35); 36 37await rejects( 38 import(jsonModuleDataUrl), 39 { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } 40); 41 42await rejects( 43 import(jsonModuleDataUrl, { assert: {} }), 44 { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } 45); 46 47await rejects( 48 import(jsonModuleDataUrl, { assert: { foo: 'bar' } }), 49 { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } 50); 51 52await rejects( 53 import(jsonModuleDataUrl, { assert: { type: 'unsupported' }}), 54 { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } 55); 56