Skip to content

Commit 3ca85da

Browse files
committed
use skipTest()
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent a94ae40 commit 3ca85da

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default defineConfig([
1717
mustNotCall: "readonly",
1818
gcUntil: "readonly",
1919
experimentalFeatures: "readonly",
20+
napiVersion: "readonly",
21+
skipTest: "readonly",
2022
},
2123
},
2224
rules: {

implementors/node/process.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const napiVersion = Number(process.versions.napi);
2+
3+
const skipTest = () => {
4+
process.exit(0);
5+
};
6+
7+
Object.assign(globalThis, { napiVersion, skipTest });

implementors/node/tests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ const GC_MODULE_PATH = path.join(
3434
"node",
3535
"gc.js"
3636
);
37+
const PROCESS_MODULE_PATH = path.join(
38+
ROOT_PATH,
39+
"implementors",
40+
"node",
41+
"process.js"
42+
);
3743
const MUST_CALL_MODULE_PATH = path.join(
3844
ROOT_PATH,
3945
"implementors",
@@ -79,6 +85,8 @@ export function runFileInSubprocess(
7985
"--import",
8086
"file://" + GC_MODULE_PATH,
8187
"--import",
88+
"file://" + PROCESS_MODULE_PATH,
89+
"--import",
8290
"file://" + MUST_CALL_MODULE_PATH,
8391
filePath,
8492
],
Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
"use strict";
22

3-
if (experimentalFeatures.sharedArrayBuffer) {
4-
// Testing api calls for arrays
5-
const test_dataview = loadAddon("test_dataview");
6-
7-
// Test for creating dataview with ArrayBuffer
8-
{
9-
const buffer = new ArrayBuffer(128);
10-
const template = Reflect.construct(DataView, [buffer]);
11-
12-
const theDataview = test_dataview.CreateDataViewFromJSDataView(template);
13-
assert.ok(
14-
theDataview instanceof DataView,
15-
`Expect ${theDataview} to be a DataView`,
16-
);
17-
}
18-
19-
// Test for creating dataview with SharedArrayBuffer
20-
{
21-
const buffer = new SharedArrayBuffer(128);
22-
const template = new DataView(buffer);
23-
24-
const theDataview = test_dataview.CreateDataViewFromJSDataView(template);
25-
assert.ok(
26-
theDataview instanceof DataView,
27-
`Expect ${theDataview} to be a DataView`,
28-
);
29-
30-
assert.strictEqual(template.buffer, theDataview.buffer);
31-
}
32-
33-
// Test for creating dataview with ArrayBuffer and invalid range
34-
{
35-
const buffer = new ArrayBuffer(128);
36-
assert.throws(() => {
37-
test_dataview.CreateDataView(buffer, 10, 200);
38-
}, RangeError);
39-
}
40-
41-
// Test for creating dataview with SharedArrayBuffer and invalid range
42-
{
43-
const buffer = new SharedArrayBuffer(128);
44-
assert.throws(() => {
45-
test_dataview.CreateDataView(buffer, 10, 200);
46-
}, RangeError);
47-
}
3+
// The addon links node_api_is_sharedarraybuffer, which is only available
4+
// when the sharedArrayBuffer experimental feature is supported.
5+
if (!experimentalFeatures.sharedArrayBuffer) {
6+
skipTest();
7+
}
8+
9+
// Testing api calls for arrays
10+
const test_dataview = loadAddon("test_dataview");
11+
12+
// Test for creating dataview with ArrayBuffer
13+
{
14+
const buffer = new ArrayBuffer(128);
15+
const template = Reflect.construct(DataView, [buffer]);
16+
17+
const theDataview = test_dataview.CreateDataViewFromJSDataView(template);
18+
assert.ok(
19+
theDataview instanceof DataView,
20+
`Expect ${theDataview} to be a DataView`,
21+
);
22+
}
23+
24+
// Test for creating dataview with SharedArrayBuffer
25+
{
26+
const buffer = new SharedArrayBuffer(128);
27+
const template = new DataView(buffer);
28+
29+
const theDataview = test_dataview.CreateDataViewFromJSDataView(template);
30+
assert.ok(
31+
theDataview instanceof DataView,
32+
`Expect ${theDataview} to be a DataView`,
33+
);
34+
35+
assert.strictEqual(template.buffer, theDataview.buffer);
36+
}
37+
38+
// Test for creating dataview with ArrayBuffer and invalid range
39+
{
40+
const buffer = new ArrayBuffer(128);
41+
assert.throws(() => {
42+
test_dataview.CreateDataView(buffer, 10, 200);
43+
}, RangeError);
44+
}
45+
46+
// Test for creating dataview with SharedArrayBuffer and invalid range
47+
{
48+
const buffer = new SharedArrayBuffer(128);
49+
assert.throws(() => {
50+
test_dataview.CreateDataView(buffer, 10, 200);
51+
}, RangeError);
4852
}

0 commit comments

Comments
 (0)