Skip to content

Commit 9c7b806

Browse files
committed
[Tests] add tests
1 parent 207e26d commit 9c7b806

File tree

9 files changed

+259
-2
lines changed

9 files changed

+259
-2
lines changed

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage/

Diff for: .eslintrc

+9
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66
"rules": {
77
"operator-linebreak": [2, "before"],
88
},
9+
10+
"overrides": [
11+
{
12+
"files": "test/**",
13+
"globals": {
14+
"SharedArrayBuffer": false,
15+
},
16+
},
17+
],
918
}

Diff for: .github/workflows/node-4+.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: 'Tests: node.js'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
matrix:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
latest: ${{ steps.set-matrix.outputs.requireds }}
10+
minors: ${{ steps.set-matrix.outputs.optionals }}
11+
steps:
12+
- uses: ljharb/actions/node/matrix@main
13+
id: set-matrix
14+
with:
15+
preset: '>=4'
16+
17+
latest:
18+
needs: [matrix]
19+
name: 'latest minors'
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix: ${{ fromJson(needs.matrix.outputs.latest) }}
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- uses: ljharb/actions/node/run@main
28+
name: 'npm install && npm run tests-only'
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
command: 'tests-only'
32+
minors:
33+
needs: [matrix, latest]
34+
name: 'non-latest minors'
35+
continue-on-error: true
36+
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
37+
runs-on: ubuntu-latest
38+
39+
strategy:
40+
matrix: ${{ fromJson(needs.matrix.outputs.minors) }}
41+
42+
steps:
43+
- uses: actions/checkout@v2
44+
- uses: ljharb/actions/node/run@main
45+
name: 'npm install && npm run tests-only'
46+
with:
47+
node-version: ${{ matrix.node-version }}
48+
command: 'tests-only'
49+
50+
node:
51+
name: 'node 4+'
52+
needs: [latest, minors]
53+
runs-on: ubuntu-latest
54+
steps:
55+
- run: 'echo tests completed'

Diff for: .github/workflows/node-iojs.yml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Tests: node.js (io.js)'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
matrix:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
latest: ${{ steps.set-matrix.outputs.requireds }}
10+
minors: ${{ steps.set-matrix.outputs.optionals }}
11+
steps:
12+
- uses: ljharb/actions/node/matrix@main
13+
id: set-matrix
14+
with:
15+
preset: 'iojs'
16+
17+
latest:
18+
needs: [matrix]
19+
name: 'latest minors'
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix: ${{ fromJson(needs.matrix.outputs.latest) }}
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- uses: ljharb/actions/node/run@main
28+
name: 'npm install && npm run tests-only'
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
command: 'tests-only'
32+
skip-ls-check: true
33+
34+
minors:
35+
needs: [matrix, latest]
36+
name: 'non-latest minors'
37+
continue-on-error: true
38+
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
39+
runs-on: ubuntu-latest
40+
41+
strategy:
42+
matrix: ${{ fromJson(needs.matrix.outputs.minors) }}
43+
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: ljharb/actions/node/run@main
47+
name: 'npm install && npm run tests-only'
48+
with:
49+
node-version: ${{ matrix.node-version }}
50+
command: 'tests-only'
51+
skip-ls-check: true
52+
53+
node:
54+
name: 'io.js'
55+
needs: [latest, minors]
56+
runs-on: ubuntu-latest
57+
steps:
58+
- run: 'echo tests completed'

Diff for: .github/workflows/node-pretest.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Tests: pretest/posttest'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
pretest:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: ljharb/actions/node/run@main
12+
name: 'npm install && npm run pretest'
13+
with:
14+
node-version: 'lts/*'
15+
command: 'pretest'
16+
17+
posttest:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: ljharb/actions/node/run@main
23+
name: 'npm install && npm run posttest'
24+
with:
25+
node-version: 'lts/*'
26+
command: 'posttest'

Diff for: .github/workflows/node-zero.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: 'Tests: node.js (0.x)'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
matrix:
7+
runs-on: ubuntu-latest
8+
outputs:
9+
stable: ${{ steps.set-matrix.outputs.requireds }}
10+
unstable: ${{ steps.set-matrix.outputs.optionals }}
11+
steps:
12+
- uses: ljharb/actions/node/matrix@main
13+
id: set-matrix
14+
with:
15+
preset: '0.x'
16+
17+
stable:
18+
needs: [matrix]
19+
name: 'stable minors'
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
matrix: ${{ fromJson(needs.matrix.outputs.stable) }}
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- uses: ljharb/actions/node/run@main
28+
name: 'npm install && npm run tests-only'
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
command: 'tests-only'
32+
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
33+
skip-ls-check: true
34+
35+
unstable:
36+
needs: [matrix, stable]
37+
name: 'unstable minors'
38+
continue-on-error: true
39+
if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }}
40+
runs-on: ubuntu-latest
41+
42+
strategy:
43+
matrix: ${{ fromJson(needs.matrix.outputs.unstable) }}
44+
45+
steps:
46+
- uses: actions/checkout@v2
47+
- uses: ljharb/actions/node/run@main
48+
name: 'npm install && npm run tests-only'
49+
with:
50+
node-version: ${{ matrix.node-version }}
51+
command: 'tests-only'
52+
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
53+
skip-ls-check: true
54+
55+
node:
56+
name: 'node 0.x'
57+
needs: [stable, unstable]
58+
runs-on: ubuntu-latest
59+
steps:
60+
- run: 'echo tests completed'

Diff for: .nycrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text-summary", "text", "html", "json"],
5+
"lines": 86,
6+
"statements": 85.93,
7+
"functions": 82.43,
8+
"branches": 76.06,
9+
"exclude": [
10+
"coverage",
11+
"test"
12+
]
13+
}

Diff for: package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"scripts": {
2020
"lint": "eslint --ext=.js,.mjs .",
2121
"pretest": "npm run lint",
22-
"test": "echo \"Error: no test specified\" && exit 1"
22+
"tests-only": "nyc tape 'test/**/*.js'",
23+
"test": "npm run tests-only --",
24+
"posttest": "aud --production"
2325
},
2426
"repository": {
2527
"type": "git",
@@ -40,6 +42,12 @@
4042
"homepage": "https://github.com/inspect-js/is-shared-array-buffer#readme",
4143
"devDependencies": {
4244
"@ljharb/eslint-config": "^17.5.1",
43-
"eslint": "^7.21.0"
45+
"aud": "^1.1.4",
46+
"es-value-fixtures": "^1.2.1",
47+
"eslint": "^7.21.0",
48+
"for-each": "^0.3.3",
49+
"nyc": "^10.3.2",
50+
"object-inspect": "^1.9.0",
51+
"tape": "^5.2.2"
4452
}
4553
}

Diff for: test/index.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
var test = require('tape');
4+
var inspect = require('object-inspect');
5+
var forEach = require('for-each');
6+
var v = require('es-value-fixtures');
7+
8+
var isSharedArrayBuffer = require('..');
9+
10+
test('isSharedArrayBuffer', function (t) {
11+
t.equal(typeof isSharedArrayBuffer, 'function', 'is a function');
12+
13+
var nonSABs = v.primitives.concat(v.objects);
14+
forEach(nonSABs, function (nonSAB) {
15+
t.equal(isSharedArrayBuffer(nonSAB), false, inspect(nonSAB) + ' is not a SharedArrayBuffer');
16+
});
17+
18+
t.test('actual SharedArrayBuffer instances', { skip: typeof SharedArrayBuffer === 'undefined' }, function (st) {
19+
var sab = new SharedArrayBuffer();
20+
21+
st.equal(isSharedArrayBuffer(sab), true, inspect(sab) + ' is a SharedArrayBuffer');
22+
23+
st.end();
24+
});
25+
26+
t.end();
27+
});

0 commit comments

Comments
 (0)