Skip to content

Commit 9716a10

Browse files
committed
Add tests and CI actions
1 parent ead45a8 commit 9716a10

File tree

7 files changed

+67
-1
lines changed

7 files changed

+67
-1
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Run tests
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
submodules: true
14+
- name: use node.js v18.x
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 18.x
18+
- run: npm ci
19+
- run: npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# used for testing only
2+
test/temporal-polyfill
3+
14
# Logs
25
logs
36
*.log

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"NOINPUT",
4+
"runtest"
5+
]
6+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Lightweight runner for ECMAScript Temporal's Test262 tests",
55
"main": "index.mjs",
66
"scripts": {
7-
"test": "echo \"No tests included yet\" && exit 1"
7+
"test": "test/test.sh"
88
},
99
"repository": {
1010
"type": "git",

test/resolve-test.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import fs from 'fs';
2+
const PKG = JSON.parse(fs.readFileSync('../../package.json', { encoding: 'utf-8' }));
3+
export function resolve(specifier, parent, defaultResolve) {
4+
if (specifier === PKG.name) {
5+
specifier = new URL('../index.mjs', import.meta.url).toString();
6+
}
7+
return defaultResolve(specifier, parent);
8+
}

test/runtest262.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copy of runtest262.mjs from https://github.com/js-temporal/temporal-polyfill/pull/204
2+
import runTest262 from '@js-temporal/temporal-test262-runner';
3+
4+
const isProduction = process.env.NODE_ENV === 'production';
5+
const isTranspiledBuild = !!process.env.TRANSPILE;
6+
7+
const expectedFailureFiles = ['test/expected-failures.txt'];
8+
if (isProduction) {
9+
expectedFailureFiles.push(isTranspiledBuild ? 'test/expected-failures-es5.txt' : 'test/expected-failures-opt.txt');
10+
}
11+
12+
const result = runTest262({
13+
test262Dir: 'test262',
14+
polyfillCodeFile: 'dist/script.js',
15+
expectedFailureFiles,
16+
testGlobs: process.argv.slice(2)
17+
});
18+
19+
process.exit(result ? 0 : 1);

test/test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
cd test
6+
rm -rf temporal-polyfill
7+
git clone --recurse-submodules https://github.com/js-temporal/temporal-polyfill.git
8+
cd temporal-polyfill
9+
npm i
10+
TEST262=1 npm run build
11+
node --loader ../resolve-test.mjs ../runtest262.mjs

0 commit comments

Comments
 (0)