Skip to content

Commit 80a5b28

Browse files
committed
test: switch to cypress
1 parent 9109f4c commit 80a5b28

12 files changed

+8719
-723
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
cypress/videos
3+
cypress/screenshots

cypress.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"testFiles": "**/*.js",
3+
"watchForFileChanges": false,
4+
"nodeVersion": "system",
5+
"baseUrl": "http://localhost:8000/cypress/integration/",
6+
"screenshotOnRunFailure": false,
7+
"video": false
8+
}

cypress/integration/app.test.js

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import * as THREE from '../../example/jsm/three.module.js';
2+
import { getDefaultOptions } from '../../src/default.options.js';
3+
import * as KLEE from '../../dist/klee.js';
4+
5+
describe('KLEE app', function () {
6+
7+
describe('init (THREE, options)', function () {
8+
9+
it('should create a THREE.WebGLRenderer with options and/or default options', () => {
10+
11+
const defaultOptions = getDefaultOptions(THREE);
12+
const defaultRendererElement = defaultOptions.renderer.domElement;
13+
const options = { renderer: { properties: { shadowMap: { enabled: false } } } };
14+
const optionsShadows = options.renderer.properties.shadowMap.enabled;
15+
16+
KLEE.App.init(THREE, options);
17+
const renderer = KLEE.App.renderer;
18+
const rendererElement = renderer.domElement.parentElement.localName;
19+
const rendererShadows = renderer.shadowMap.enabled;
20+
21+
expect(renderer).to.be.an.instanceof(THREE.WebGLRenderer);
22+
expect(rendererElement).to.be.equal(defaultRendererElement);
23+
expect(rendererShadows).to.be.equal(optionsShadows);
24+
25+
renderer.dispose();
26+
27+
});
28+
29+
it('throws an error, when no THREE is given', () => {
30+
31+
expect(() => KLEE.App.init()).to.throw();
32+
expect(() => KLEE.App.init(2)).to.throw();
33+
expect(() => KLEE.App.init('some-string')).to.throw();
34+
35+
});
36+
37+
});
38+
39+
describe('create (options)', function () {
40+
41+
it('should create a THREE object width a THREE method and some args', () => {
42+
43+
const material = {
44+
type: 'MeshBasicMaterial',
45+
args: [{ color: 0x00ff00 }]
46+
};
47+
const materialColor = new THREE.Color(material.args[0].color);
48+
49+
const materialObject = KLEE.App.create(material);
50+
51+
expect(materialObject.color).to.be.eql(materialColor);
52+
expect(materialObject).to.be.an.instanceof(THREE.MeshBasicMaterial);
53+
54+
});
55+
56+
});
57+
58+
describe('initSize ()', function () {
59+
60+
it('it should set the size of the renderer and the camera aspect');
61+
62+
});
63+
64+
describe('run (callback)', function () {
65+
66+
it('it sets the requestAnimationFrame and runs an optional callback inside');
67+
68+
});
69+
70+
describe('error (message)', function () {
71+
72+
it('throws and error with arguments message', () => {
73+
74+
const message = 'Error message';
75+
76+
expect(() => KLEE.App.error(message)).to.throw(message);
77+
78+
});
79+
80+
});
81+
82+
describe('warn (message)', function () {
83+
84+
it('shows a warning in console with message if debugLevel > 0');
85+
86+
});
87+
88+
describe('log (message)', function () {
89+
90+
it('shows log in console with message if debugLevel > 1');
91+
92+
});
93+
94+
describe('info (message)', function () {
95+
96+
it('shows info in console with message if debugLevel > 2');
97+
98+
});
99+
100+
describe('setter', function () {
101+
102+
it('scene, set the THREE.Scene');
103+
it('camera, set the THREE.Camera');
104+
it('controls, set the THREE.Controls');
105+
106+
});
107+
108+
describe('getter', function () {
109+
110+
it('options, returns the options set from init');
111+
it('THREE, returns the THREE module set from init');
112+
it('scene, returns the generated THREE.Scene');
113+
it('camera, returns the generated THREE.Camera');
114+
it('controls, returns the generated THREE.Controls');
115+
it('renderer, returns the generated THREE.Renderer');
116+
117+
});
118+
119+
});

cypress/integration/default.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Tests</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
</head>
8+
<body>
9+
<h1>Test</h1>
10+
</body>
11+
</html>
12+

cypress/integration/light.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as THREE from '../../example/jsm/three.module.js';
2+
// import { getDefaultOptions } from '../src/default.options.js';
3+
import * as KLEE from '../../dist/klee.js';
4+
5+
describe('KLEE light', function () {
6+
7+
describe('add (options)', function () {
8+
9+
it('should add one or more THREE light objects to the scene');
10+
11+
});
12+
13+
describe('create (options)', function () {
14+
15+
it('should create a THREE light object', () => {
16+
17+
const testNameProperty = 'This-Is-Test-DirectionalLight';
18+
const options = {
19+
type: 'DirectionalLight',
20+
properties: { name: testNameProperty }
21+
};
22+
23+
const light = KLEE.Light.create(options);
24+
25+
expect(light.name).to.be.equal(testNameProperty);
26+
expect(light).to.be.an.instanceof(THREE.DirectionalLight);
27+
28+
});
29+
30+
});
31+
32+
describe('change (light, options)', function () {
33+
34+
it('should chane the properties of a THREE light object');
35+
36+
});
37+
38+
});

cypress/integration/utils.test.js

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Utils } from '../../src/utils.js';
2+
3+
describe('Utils', function () {
4+
5+
describe('merge (target, source)', function () {
6+
7+
it('should return a merge of two nested objects or the target object', () => {
8+
9+
const target = {
10+
foo1: 'foo1',
11+
foo2: {
12+
foo3: 'foo3'
13+
}
14+
};
15+
16+
const source = {
17+
bar1: 'bar1',
18+
foo2: {
19+
foo3: 'bar3'
20+
},
21+
bar4: 'bar4'
22+
};
23+
24+
const expectedMerge = {
25+
foo1: 'foo1',
26+
foo2: {
27+
foo3: 'bar3'
28+
},
29+
bar1: 'bar1',
30+
bar4: 'bar4'
31+
};
32+
33+
const noSrcResult = Utils.merge(target);
34+
const result = Utils.merge(target, source);
35+
36+
expect(JSON.stringify(noSrcResult)).to.equal(JSON.stringify(target));
37+
expect(JSON.stringify(result)).to.equal(JSON.stringify(expectedMerge));
38+
39+
});
40+
41+
});
42+
43+
describe('isThreeColorValue (string)', function () {
44+
45+
it('should return true if string is a THREE object property key that has a color value otherwise false', () => {
46+
47+
const threeColorValues = [
48+
49+
'color',
50+
'specular',
51+
'emissive',
52+
'diffuse',
53+
'background'
54+
55+
];
56+
57+
const noColorValues = [
58+
59+
true,
60+
{ test: 'test' },
61+
'blue',
62+
'colors',
63+
'backgrounds'
64+
65+
];
66+
67+
const expectedTruely = [true, true, true, true, true];
68+
const expectedFalsy = [false, false, false, false, false];
69+
70+
const trulyResults = threeColorValues.map(color => Utils.isThreeColorValue(color));
71+
const falsyResults = noColorValues.map(color => Utils.isThreeColorValue(color));
72+
73+
expect(trulyResults).to.eql(expectedTruely);
74+
expect(falsyResults).to.eql(expectedFalsy);
75+
76+
});
77+
78+
});
79+
80+
describe('applyMethods (object, methods)', function () {
81+
82+
it('should call methods of an object and returns the object', () => {
83+
84+
class TestClass {
85+
86+
constructor () {
87+
88+
this.result1 = null;
89+
this.result2 = null;
90+
91+
}
92+
93+
method1 (x, y) {
94+
95+
this.result1 = x + y;
96+
97+
}
98+
99+
method2 () {
100+
101+
this.result2 = true;
102+
103+
}
104+
105+
}
106+
107+
const testMethods = {
108+
109+
method1: [2, 3],
110+
method2: [],
111+
method3: []
112+
113+
};
114+
115+
const testObject = new TestClass();
116+
117+
const resultObject = Utils.applyMethods(testObject, testMethods);
118+
const result1 = resultObject.result1;
119+
const result2 = resultObject.result2;
120+
121+
expect(resultObject).to.equal(testObject);
122+
expect(result1).to.equal(5);
123+
expect(result2).to.be.true;
124+
125+
});
126+
127+
});
128+
129+
});

cypress/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/plugins/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
};

cypress/support/commands.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

cypress/support/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)