Skip to content

Commit

Permalink
Run Test262 tests against production artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
12wrigja committed Sep 16, 2021
1 parent 6d3588c commit 973c602
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 32 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ jobs:
node-version: 14.x
- run: npm ci --no-optional
- run: npm test
test-test262:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: use node.js v16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- run: npm ci
- run: npm run test262
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ tsc-out/
.vscode/*
!.vscode/launch.json
*.tgz
test/tc39
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ types
tsconfig.json
*.sh
.vscode
dist/script.js
dist/playground.cjs
26 changes: 0 additions & 26 deletions lib/init.cjs

This file was deleted.

42 changes: 42 additions & 0 deletions lib/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This is an alternate entry point that polyfills Temporal onto the global
// object. This is used only for the browser playground and the test262 tests.
// See the note in index.mjs.

import * as Temporal from './temporal';
import * as Intl from './intl';
import { toTemporalInstant } from './legacydate';

Object.defineProperty(globalThis, 'Temporal', {
value: {},
writable: true,
enumerable: false,
configurable: true
});
copy(globalThis.Temporal, Temporal);
Object.defineProperty(globalThis.Temporal, Symbol.toStringTag, {
value: 'Temporal',
writable: false,
enumerable: false,
configurable: true
});
copy(globalThis.Temporal.Now, Temporal.Now);
copy(globalThis.Intl, Intl);
Object.defineProperty(globalThis.Date.prototype, 'toTemporalInstant', {
value: toTemporalInstant,
writable: true,
enumerable: false,
configurable: true
});

function copy(target, source) {
for (const prop of Object.getOwnPropertyNames(source)) {
Object.defineProperty(target, prop, {
value: source[prop],
writable: true,
enumerable: false,
configurable: true
});
}
}

export { Temporal, Intl, toTemporalInstant };
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"types": "./index.d.ts",
"scripts": {
"test": "tsc && node --no-warnings --experimental-modules --experimental-specifier-resolution=node --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
"build": "rollup -c rollup.config.js",
"test262": "./test/test262.sh",
"build": "rm -rf dist/* && rollup -c rollup.config.js",
"prepare": "npm run build",
"prepublishOnly": "npm run build",
"playground": "npm run build && node --experimental-modules --no-warnings --icu-data-dir node_modules/full-icu -r ./lib/init.cjs",
"playground": "TEMPORAL_PLAYGROUND=1 npm run build && node --experimental-modules --no-warnings --icu-data-dir node_modules/full-icu -r ./dist/playground.cjs",
"lint": "eslint . --ext ts,js,mjs,.d.ts --max-warnings 0 --cache \"$@\"",
"postlint": "npm run tscheck",
"pretty": "eslint . --ext ts,js,mjs,.d.ts --fix",
Expand Down
41 changes: 38 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import { terser } from 'rollup-plugin-terser';
import { env } from 'process';
import pkg from './package.json';

const isProduction = env.NODE_ENV === 'production';
const isPlaygroundBuild = !!env.TEMPORAL_PLAYGROUND;
const isTest262 = !!env.TEST262;
const isProduction = env.NODE_ENV === 'production' && !isTest262;
const libName = 'temporal';

const plugins = [
typescript({
typescript: require('typescript')
}),
replace({ exclude: 'node_modules/**', 'globalThis.__debug__': !isProduction, preventAssignment: true }),
replace({ exclude: 'node_modules/**', 'globalThis.__debug__': !isTest262 && !isProduction, preventAssignment: true }),
resolve({ preferBuiltins: false }),
commonjs(),
babel({
Expand Down Expand Up @@ -51,7 +53,7 @@ function outputEntry(file, format) {
};
}

export default [
let builds = [
{
input,
external,
Expand All @@ -74,3 +76,36 @@ export default [
plugins
}
];

if (isTest262) {
builds = [
{
input: 'lib/init.ts',
output: {
name: libName,
file: 'dist/script.js',
format: 'iife',
sourcemap: true
},
plugins
}
];
}

if (isPlaygroundBuild) {
builds = [
{
input: 'lib/init.ts',
output: {
name: libName,
file: 'dist/playground.cjs',
format: 'cjs',
exports: 'named',
sourcemap: true
},
plugins
}
];
}

export default builds;
18 changes: 18 additions & 0 deletions test/test262.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"
if [ ! -d "tc39" ]; then
git clone --depth=1 https://github.com/tc39/proposal-temporal.git tc39
else
cd ./tc39
git fetch origin
git merge --ff-only origin/main
fi

cd ../ && TEST262=1 npm run build
cd tc39/polyfill && npm install
if [ ! -z "$TESTS" ]; then
PRELUDE=../../../dist/script.js npm run test262 "$TESTS"
else
PRELUDE=../../../dist/script.js npm run test262
fi
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// "strictNullChecks": true,
// "strictPropertyInitialization": true,
"stripInternal": true,
"target": "es5",
"target": "es2015",
"outDir": "tsc-out/",
"types": []
},
Expand Down

0 comments on commit 973c602

Please sign in to comment.