Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Aug 29, 2021
1 parent fc176c4 commit 1f85c01
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
34 changes: 21 additions & 13 deletions test/es-module/test-esm-dynamic-import-assertion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@
import '../common/index.mjs';
import { rejects, strictEqual } from 'assert';

const jsModuleUrl = 'data:text/javascript,export{}';
const jsModuleDataUrl = 'data:text/javascript,export{}';

await rejects(
import(`data:text/javascript,import${JSON.stringify(jsModuleUrl)}assert{type:"json"}`),
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}assert{type:"json"}`),
{ code: 'ERR_FAILED_IMPORT_ASSERTION' }
);

await rejects(
import(jsModuleUrl, {assert:{type:'json'}}),
import(jsModuleDataUrl, { assert: { type: 'json' } }),
{ code: 'ERR_FAILED_IMPORT_ASSERTION' }
);

{
const secret = await import(
'../fixtures/experimental.json',
{assert: { type: 'json' }}
);
const [secret0, secret1] = await Promise.all([
import('../fixtures/experimental.json'),
import(
'../fixtures/experimental.json',
{ assert: { type: 'json' } }
),
]);

strictEqual(secret.default.ofLife, 42);
strictEqual(secret0.default.ofLife, 42);
strictEqual(secret1.default.ofLife, 42);
}

{
const secret = await import(
'data:application/json,{"ofLife":42}',
{assert: { type: 'json' }}
);
const [secret0, secret1] = await Promise.all([
import('data:application/json,{"ofLife":42}'),
import(
'data:application/json,{"ofLife":42}',
{ assert: { type: 'json' } }
),
]);

strictEqual(secret.default.ofLife, 42);
strictEqual(secret0.default.ofLife, 42);
strictEqual(secret1.default.ofLife, 42);
}
9 changes: 9 additions & 0 deletions test/es-module/test-esm-import-assertion-3.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

import secret0 from '../fixtures/experimental.json' assert { type: 'json' };
import secret1 from '../fixtures/experimental.json';

strictEqual(secret0.ofLife, 42);
strictEqual(secret1.ofLife, 42);

0 comments on commit 1f85c01

Please sign in to comment.