Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Feb 23, 2021
1 parent 322bf04 commit 31fcbd1
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 57 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Then, access http://localhost:8082/ with your web browser.
### Prerequisites
* Node.js 12.18.1 or later
* Node.js 14.15.5 or later
### Setup Project
Expand Down Expand Up @@ -183,6 +183,24 @@ $ npm run doc
$ npm run test
```
You can execute a part of tests like this.
### For unit test
```bash
$ npm run test-unit -- ./src/foundation/core
```
```bash
$ npm run test-unit -- ./src/foundation/core/Entity.test.ts
```
### For E2E (visual) test
```bash
$ npm run test-e2e -- ./samples/test_e2e/FastestInstancedDrawingWebGL1
```
Some of the E2E (visual) tests might fail due to GPU environment differences.
The official test environment is our Github Action CI Runner instance.
Expand Down
19 changes: 11 additions & 8 deletions build-samples.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const exec = require('child_process').exec;
const sampleList = require('./samples/sample-list.json');


function build(sampleDir){
for (let sampleName of sampleList[sampleDir]) {
exec(`npx tsc ./samples/${sampleDir}/${sampleName}/main.ts --lib es2017,dom --target es2017 --module umd --moduleResolution node --sourceMap`, (err, stdout, stderr) => {
if (err) { console.log(err); }
console.log(stdout);
});
function build(sampleDir) {
for (const sampleName of sampleList[sampleDir]) {
exec(
`npx tsc ./samples/${sampleDir}/${sampleName}/main.ts --lib es2017,dom --target es2017 --module umd --moduleResolution node --sourceMap`,
(err, stdout, stderr) => {
if (err) {
console.log(err);
}
console.log(stdout);
}
);
}
}

build('simple');
build('test_e2e');

File renamed without changes.
21 changes: 7 additions & 14 deletions jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
module.exports = {
"preset": "jest-puppeteer",
"transform": {
"^.+\\.tsx?$": "ts-jest"
preset: 'jest-puppeteer',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFilesAfterEnv": [require.resolve("./setup.js")],
"rootDir": process.cwd(),
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFilesAfterEnv: [require.resolve('./jest-e2e-setup.js')],
rootDir: process.cwd(),
};
21 changes: 7 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
module.exports = {
"transform": {
"^.+\\.tsx?$": "ts-jest",
"\\.(vert|frag|glsl)$": "<rootDir>/jest-webpack-shaderity.js",
"\\VERSION-FILE$": "<rootDir>/jest-webpack-shaderity.js"
transform: {
'^.+\\.tsx?$': 'ts-jest',
'\\.(vert|frag|glsl)$': '<rootDir>/jest-webpack-shaderity.js',
'\\VERSION-FILE$': '<rootDir>/jest-webpack-shaderity.js',
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"rootDir": process.cwd(),
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
rootDir: process.cwd(),
};
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
"build-type": "tsc --emitDeclarationOnly",
"build-samples": "node build-samples",
"prepublishOnly": "npm run build && npm run test",
"test": "npm run test-unit && npm run test-e2e",
"test-unit": "npx jest --config jest.config.js ./src",
"test-e2e": "npx jest ./samples/test_e2e --runInBand --config jest.config.e2e.js",
"test": "npm run test-unit-all && npm run test-e2e-all",
"test-unit-all": "npm run test-unit -- ./src",
"test-unit": "npx jest --config jest.config.js",
"test-e2e-all": "npm run test-e2e -- ./samples/test_e2e",
"test-e2e": "npx jest --config jest.config.e2e.js",
"test-e2e-update": "npx jest ./samples/test_e2e --runInBand --config jest.config.e2e.js --updateSnapshot",
"test-coverage": "npx jest --coverage",
"doc": "typedoc --exclude '**/*+(test|d).ts' --out ./docs/api/ ./src/",
Expand Down
9 changes: 3 additions & 6 deletions samples/test_e2e/FastestInstancedDrawingWebGL1/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ declare const Rn: typeof _Rn;
}

const startTime = Date.now();
let p = null;
const rotationVec3 = Rn.MutableVector3.zero();
let count = 0;

Expand All @@ -327,12 +326,10 @@ declare const Rn: typeof _Rn;
const stats = new Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.domElement);

const draw = function () {
if (p == null && count > 0) {
p = document.createElement('p');
p.setAttribute('id', 'rendered');
p.innerText = 'Rendered.';
document.body.appendChild(p);
if (count > 0) {
window._rendered = true;
}

const date = new Date();
Expand Down
2 changes: 1 addition & 1 deletion samples/test_e2e/FastestInstancedDrawingWebGL1/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test('regression test DataTextureInstancedDrawingWebGL1', async () => {
'http://localhost:8082/samples/test_e2e/FastestInstancedDrawingWebGL1'
);
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 600000});
await page.waitForFunction(() => {return window._rendered});
const canvasElement = await page.$('#world');
const image = await canvasElement.screenshot();
expect(image).toMatchImageSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ document.body.appendChild(p);
mouseUpCount = count;
});

draw();

function draw() {
switch (count) {
case 1:
Expand Down Expand Up @@ -93,4 +91,6 @@ document.body.appendChild(p);

requestAnimationFrame(draw);
}

draw();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ test('regression test GltfImporter-walk-through-eye-direction-moving', async ()
'http://localhost:8082/samples/test_e2e/GltfImporter-walk-through-eye-direction-moving'
);
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#rendered', {timeout: 600000});
await page.waitForSelector('p#rendered', {timeout: 500000});

await page.mouse.down();
await page.mouse.move(0, 0);
await page.mouse.move(0, 100);
await page.mouse.up();

await page.waitForSelector('p#moved', {timeout: 600000});
await page.waitForSelector('p#moved', {timeout: 10000});

const canvasElement = await page.$('#world');
const image = await canvasElement.screenshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test('regression test GltfImporter-walk-through-fixed-direction-moving', async (
'http://localhost:8082/samples/test_e2e/GltfImporter-walk-through-fixed-direction-moving'
);
await page.setViewport({width: 1000, height: 1000});
await page.waitForSelector('p#moved', {timeout: 600000});
await page.waitForSelector('p#moved', {timeout: 600001});

const canvasElement = await page.$('#world');
const image = await canvasElement.screenshot();
Expand Down
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
let express = require('express');
express.static.mime.define({'application/javascript': ['mjs']})
let app = express();
const express = require('express');
express.static.mime.define({'application/javascript': ['mjs']});
const app = express();
app.use(express.static('./'));

let port = 8082;
app.listen(port, ()=> {
const port = 8082;
app.listen(port, () => {
console.log('Express server is running at http://localhost:' + port);
});

0 comments on commit 31fcbd1

Please sign in to comment.