• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --experimental-loader ./test/fixtures/es-module-loaders/assertionless-json-import.mjs
2'use strict';
3const common = require('../common');
4const { strictEqual } = require('assert');
5
6async function test() {
7  {
8    const [secret0, secret1] = await Promise.all([
9      import('../fixtures/experimental.json'),
10      import(
11        '../fixtures/experimental.json',
12        { with: { type: 'json' } }
13      ),
14    ]);
15
16    strictEqual(secret0.default.ofLife, 42);
17    strictEqual(secret1.default.ofLife, 42);
18    strictEqual(secret0.default, secret1.default);
19    strictEqual(secret0, secret1);
20  }
21
22  {
23    const [secret0, secret1] = await Promise.all([
24      import('../fixtures/experimental.json?test'),
25      import(
26        '../fixtures/experimental.json?test',
27        { with: { type: 'json' } }
28      ),
29    ]);
30
31    strictEqual(secret0.default.ofLife, 42);
32    strictEqual(secret1.default.ofLife, 42);
33    strictEqual(secret0.default, secret1.default);
34    strictEqual(secret0, secret1);
35  }
36
37  {
38    const [secret0, secret1] = await Promise.all([
39      import('../fixtures/experimental.json#test'),
40      import(
41        '../fixtures/experimental.json#test',
42        { with: { type: 'json' } }
43      ),
44    ]);
45
46    strictEqual(secret0.default.ofLife, 42);
47    strictEqual(secret1.default.ofLife, 42);
48    strictEqual(secret0.default, secret1.default);
49    strictEqual(secret0, secret1);
50  }
51
52  {
53    const [secret0, secret1] = await Promise.all([
54      import('../fixtures/experimental.json?test2#test'),
55      import(
56        '../fixtures/experimental.json?test2#test',
57        { with: { type: 'json' } }
58      ),
59    ]);
60
61    strictEqual(secret0.default.ofLife, 42);
62    strictEqual(secret1.default.ofLife, 42);
63    strictEqual(secret0.default, secret1.default);
64    strictEqual(secret0, secret1);
65  }
66
67  {
68    const [secret0, secret1] = await Promise.all([
69      import('data:application/json,{"ofLife":42}'),
70      import(
71        'data:application/json,{"ofLife":42}',
72        { with: { type: 'json' } }
73      ),
74    ]);
75
76    strictEqual(secret0.default.ofLife, 42);
77    strictEqual(secret1.default.ofLife, 42);
78  }
79}
80
81test().then(common.mustCall());
82