node/test/es-module/test-esm-loader-stringify-text.mjs
Jacob df22736d80 esm: consolidate ESM loader hooks
doc: update ESM hook examples

esm: fix unsafe primordial

doc: fix ESM example linting

esm: allow source of type ArrayBuffer

doc: update ESM hook changelog to include resolve format

esm: allow all ArrayBuffers and TypedArrays for load hook source

doc: tidy code & API docs

doc: convert ESM source table header from Title Case to Sentence case

doc: add detailed explanation for getPackageType

esm: add caveat that ESMLoader::import() must NOT be renamed

esm: tidy code declaration of getFormat protocolHandlers

doc: correct ESM doc link (bad conflict resolution)

doc: update ESM hook limitation for CJS

esm: tweak preload description

doc: update ESM getPackageType() example explanation

PR-URL: https://github.com/nodejs/node/pull/37468
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2021-09-11 18:08:35 -07:00

91 lines
2.3 KiB
JavaScript

// Flags: --experimental-loader ./test/fixtures/es-module-loaders/string-sources.mjs
import { mustCall, mustNotCall } from '../common/index.mjs';
import assert from 'assert';
import('test:Array').then(
mustNotCall('Should not accept Arrays'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
import('test:ArrayBuffer').then(
mustCall(),
mustNotCall('Should accept ArrayBuffers'),
);
import('test:BigInt64Array').then(
mustCall(),
mustNotCall('Should accept BigInt64Array'),
);
import('test:BigUint64Array').then(
mustCall(),
mustNotCall('Should accept BigUint64Array'),
);
import('test:Float32Array').then(
mustCall(),
mustNotCall('Should accept Float32Array'),
);
import('test:Float64Array').then(
mustCall(),
mustNotCall('Should accept Float64Array'),
);
import('test:Int8Array').then(
mustCall(),
mustNotCall('Should accept Int8Array'),
);
import('test:Int16Array').then(
mustCall(),
mustNotCall('Should accept Int16Array'),
);
import('test:Int32Array').then(
mustCall(),
mustNotCall('Should accept Int32Array'),
);
import('test:null').then(
mustNotCall('Should not accept null'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
import('test:Object').then(
mustNotCall('Should not stringify or valueOf Objects'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
import('test:SharedArrayBuffer').then(
mustCall(),
mustNotCall('Should accept SharedArrayBuffers'),
);
import('test:string').then(
mustCall(),
mustNotCall('Should accept strings'),
);
import('test:String').then(
mustNotCall('Should not accept wrapper Strings'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
import('test:Uint8ClampedArray').then(
mustCall(),
mustNotCall('Should accept Uint8ClampedArray'),
);
import('test:Uint16Array').then(
mustCall(),
mustNotCall('Should accept Uint16Array'),
);
import('test:Uint32Array').then(
mustCall(),
mustNotCall('Should accept Uint32Array'),
);
import('test:Uint8Array').then(
mustCall(),
mustNotCall('Should accept Uint8Arrays'),
);
import('test:undefined').then(
mustNotCall('Should not accept undefined'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);