11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst { validateAttributes } = require('internal/modules/esm/assert');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst url = 'test://';
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciassert.ok(validateAttributes(url, 'builtin', {}));
121cb0ef41Sopenharmony_ciassert.ok(validateAttributes(url, 'commonjs', {}));
131cb0ef41Sopenharmony_ciassert.ok(validateAttributes(url, 'json', { type: 'json' }));
141cb0ef41Sopenharmony_ciassert.ok(validateAttributes(url, 'module', {}));
151cb0ef41Sopenharmony_ciassert.ok(validateAttributes(url, 'wasm', {}));
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'json', {}), {
181cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING',
191cb0ef41Sopenharmony_ci});
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'json', { type: 'json', unsupportedAttribute: 'value' }), {
221cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'module', { unsupportedAttribute: 'value' }), {
261cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'module', { type: 'json' }), {
301cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED',
311cb0ef41Sopenharmony_ci});
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// The HTML spec specifically disallows this for now, while Wasm module import
341cb0ef41Sopenharmony_ci// and whether it will require a type assertion is still an open question.
351cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'module', { type: 'javascript' }), {
361cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED',
371cb0ef41Sopenharmony_ci});
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'module', { type: 'css' }), {
401cb0ef41Sopenharmony_ci  code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED',
411cb0ef41Sopenharmony_ci});
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ciassert.throws(() => validateAttributes(url, 'module', { type: false }), {
441cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
451cb0ef41Sopenharmony_ci});
46