Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tool to write multi-module tests in a single file #4170

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Creates extensible arrays
flags: [module]
includes: [propertyHelper.js]
features: [import-attributes, json-modules]
---*/

import value from './json-value-array_FIXTURE.json' with { type: 'json' };

value.test262property = 'test262 value';

verifyProperty(value, 'test262property', {
value: 'test262 value',
writable: true,
enumerable: true,
configurable: true
});
```

## json-value-array_FIXTURE.json

```json
[]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-extensibility-array.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Creates extensible arrays
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Creates extensible objects
flags: [module]
includes: [propertyHelper.js]
features: [import-attributes, json-modules]
---*/

import value from './json-value-object_FIXTURE.json' with { type: 'json' };

value.test262property = 'test262 value';

verifyProperty(value, 'test262property', {
value: 'test262 value',
writable: true,
enumerable: true,
configurable: true
});
```

## json-value-object_FIXTURE.json

```json
{}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-extensibility-object.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Creates extensible objects
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: The same object representation is returned to all import sites
flags: [module, async]
features: [import-attributes, json-modules, globalThis, dynamic-import]
---*/

import viaStaticImport1 from './json-idempotency_FIXTURE.json' with { type: 'json' };
import {default as viaStaticImport2} from './json-idempotency_FIXTURE.json' with { type: 'json' };
import './json-idempotency-indirect_FIXTURE.js';

assert.sameValue(viaStaticImport1, viaStaticImport2);
assert.sameValue(globalThis.viaSecondModule, viaStaticImport1);

import('./json-idempotency_FIXTURE.json', { with: { type: 'json' } })
.then(function(viaDynamicImport) {
assert.sameValue(viaDynamicImport.default, viaStaticImport1);
})
.then($DONE, $DONE);
```

## json-idempotency_FIXTURE.json

```json
{}
```

## json-idempotency-indirect_FIXTURE.js

```js
import value from './json-idempotency_FIXTURE.json' with { type: 'json' };

globalThis.viaSecondModule = value;
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-idempotency.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-idempotency.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: The same object representation is returned to all import sites
Expand Down
36 changes: 36 additions & 0 deletions test/language/import/import-attributes/json-invalid.multi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Does not define
info: |
# 1.4 ParseJSONModule ( source )

The abstract operation ParseJSONModule takes a single argument source which
is a String representing the contents of a module.

1. Let json be ? Call(%JSON.parse%, undefined, « source »).
2. Return CreateDefaultExportSyntheticModule(json).
flags: [module]
features: [import-attributes, json-modules]
negative:
phase: parse
type: SyntaxError
---*/

$DONOTEVALUATE();

import value from './json-invalid_FIXTURE.json' with { type: 'json' };
```

## json-invalid_FIXTURE.json

```json
{
notJson: 0
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-invalid.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Does not define
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Does not define named bindings
info: |
In the early design of JSON modules, contributors considered allowing the
properties of object values in JSON modules to be imported directly by name.
This was ultimately rejected, so attempting to import in this way should
produce a SyntaxError.
flags: [module]
features: [import-attributes, json-modules]
negative:
phase: parse
type: SyntaxError
---*/

$DONOTEVALUATE();

import {name} from './json-named-bindings_FIXTURE.json' with { type: 'json' };
```

## json-named-bindings_FIXTURE.json

```json
{
"name": 0
}
```

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": 0
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-named-bindings.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Does not define named bindings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Correctly parses the JSON representation of an array
info: |
# 1.4 ParseJSONModule ( source )

The abstract operation ParseJSONModule takes a single argument source which
is a String representing the contents of a module.

1. Let json be ? Call(%JSON.parse%, undefined, « source »).
2. Return CreateDefaultExportSyntheticModule(json).

To more fully verify parsing correctness, the source text of the imported
module record includes non-printable characters (specifically, all four forms
of JSON's so-called "whitespace" token) both before and after the "value."
flags: [module]
features: [import-attributes, json-modules]
---*/

import value from './json-value-array_FIXTURE.json' with { type: 'json' };

assert(Array.isArray(value), 'the exported value is an array');
assert.sameValue(
Object.getPrototypeOf(value),
Array.prototype,
'the exported value is not a subclass of Array'
);
assert.sameValue(Object.getOwnPropertyNames(value).length, 7);
assert.sameValue(value.length, 6);

assert.sameValue(value[0], -1.2345);
assert.sameValue(value[1], true);
assert.sameValue(value[2], 'a string value');
assert.sameValue(value[3], null);

assert.sameValue(Object.getPrototypeOf(value[4]), Object.prototype);
assert.sameValue(Object.getOwnPropertyNames(value[4]).length, 0);

assert(Array.isArray(value[5]), 'the fifth element is an array');
assert.sameValue(
Object.getPrototypeOf(value[5]),
Array.prototype,
'the fifth element is not a subclass of Array'
);
assert.sameValue(Object.getOwnPropertyNames(value[5]).length, 1);
```

## json-value-array_FIXTURE.json

```json
[
-1234.500e-003,
true,
"a string value",
null,
{},
[]
]
```
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

[
[
-1234.500e-003,
true,
"a string value",
null,
{},
[]
]

]
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-value-array.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Correctly parses the JSON representation of an array
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Copyright (C) 2021 the V8 project authors. All rights reserved.
This code is governed by the BSD license found in the LICENSE file.

## main.js

```js
/*---
esid: sec-parse-json-module
description: Correctly parses the JSON representation of a boolean
info: |
# 1.4 ParseJSONModule ( source )

The abstract operation ParseJSONModule takes a single argument source which
is a String representing the contents of a module.

1. Let json be ? Call(%JSON.parse%, undefined, « source »).
2. Return CreateDefaultExportSyntheticModule(json).
flags: [module]
features: [import-attributes, json-modules]
---*/

import value from './json-value-boolean_FIXTURE.json' with { type: 'json' };

assert.sameValue(value, true);
```

## json-value-boolean_FIXTURE.json

```json
true
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// THIS FILE IS AUTOGENERATED. DO NOT EDIT DIRECTLY.
// TO MAKE CHANGES, EDIT ../json-value-boolean.multi.md

// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-parse-json-module
description: Correctly parses the JSON representation of a boolean
Expand Down
Loading
Loading