1// Flags: --expose-internals 2'use strict'; 3require('../common'); 4 5const assert = require('assert'); 6 7const { validateAttributes } = require('internal/modules/esm/assert'); 8 9const url = 'test://'; 10 11assert.ok(validateAttributes(url, 'builtin', {})); 12assert.ok(validateAttributes(url, 'commonjs', {})); 13assert.ok(validateAttributes(url, 'json', { type: 'json' })); 14assert.ok(validateAttributes(url, 'module', {})); 15assert.ok(validateAttributes(url, 'wasm', {})); 16 17assert.throws(() => validateAttributes(url, 'json', {}), { 18 code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING', 19}); 20 21assert.throws(() => validateAttributes(url, 'json', { type: 'json', unsupportedAttribute: 'value' }), { 22 code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', 23}); 24 25assert.throws(() => validateAttributes(url, 'module', { unsupportedAttribute: 'value' }), { 26 code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', 27}); 28 29assert.throws(() => validateAttributes(url, 'module', { type: 'json' }), { 30 code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED', 31}); 32 33// The HTML spec specifically disallows this for now, while Wasm module import 34// and whether it will require a type assertion is still an open question. 35assert.throws(() => validateAttributes(url, 'module', { type: 'javascript' }), { 36 code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED', 37}); 38 39assert.throws(() => validateAttributes(url, 'module', { type: 'css' }), { 40 code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED', 41}); 42 43assert.throws(() => validateAttributes(url, 'module', { type: false }), { 44 code: 'ERR_INVALID_ARG_TYPE', 45}); 46