Skip to content

Switch GDJS browser tests to Vitest #7685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions GDJS/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ npm install
Then launch tests:

```bash
npm run test:watch # This will use Chrome Headless
npm run test:watch # Runs tests in a headless browser using Vitest
npm run test-benchmark:watch # This will also run benchmarks
npm run test:firefox:watch # To run tests using Firefox
```

> ⚠️ If you're working on GDJS or extensions, make sure to have the development version of GDevelop running so that changes in GDJS or extension files are rebuilt (or run `npm run build` in `GDJS/`, but better run GDevelop so that any changes are watched).
Expand All @@ -23,7 +22,7 @@ npm run test:firefox:watch # To run tests using Firefox

### Unit tests

Tests are launched using Chrome. You need Chrome installed to run them. You can change the browser by modifying the package.json "test" command and install the appropriate karma package.
Tests are launched using [Vitest](https://vitest.dev/) in a headless browser. You can change the browser by editing the `vitest.config.js` file.

Tests are located in the **tests** folder for the game engine, or directly in the folder of the tested extensions.

Expand Down
4 changes: 2 additions & 2 deletions GDJS/tests/benchmarks/force.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('gdjs.Force', function() {
it('benchmark setting angle and length', function(){
this.timeout(20000);
it('benchmark setting angle and length', function(){
vi.setTimeout(20000);
var layer = new gdjs.Force();

const benchmarkSuite = makeBenchmarkSuite();
Expand Down
2 changes: 1 addition & 1 deletion GDJS/tests/benchmarks/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('gdjs.Layer', function() {
var runtimeScene = new gdjs.RuntimeScene(runtimeGame);

it('benchmark convertCoords and convertInverseCoords', function() {
this.timeout(30000);
vi.setTimeout(30000);
var layer = new gdjs.Layer(
{ name: 'My layer',
visibility: true,
Expand Down
2 changes: 1 addition & 1 deletion GDJS/tests/benchmarks/polygon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('gdjs.Polygon', function() {
it('benchmark gdjs.Polygon.collisionTest between two polygons', function() {
this.timeout(20000);
vi.setTimeout(20000);
var rect1 = gdjs.Polygon.createRectangle(32, 40);
var rect2 = gdjs.Polygon.createRectangle(32, 40);
var rect3 = gdjs.Polygon.createRectangle(32, 40);
Expand Down
8 changes: 4 additions & 4 deletions GDJS/tests/benchmarks/runtimeobject.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
describe('gdjs.RuntimeObject', function() {
const runtimeScene = new gdjs.RuntimeScene(null);

it('benchmark getAABB of rotated vs non rotated objects', function(){
this.timeout(20000);
it('benchmark getAABB of rotated vs non rotated objects', function(){
vi.setTimeout(20000);
var object = new gdjs.RuntimeObject(runtimeScene, {name: "obj1", type: "", behaviors: [], effects: []});
object.getWidth = function() { return 10; };
object.getHeight = function() { return 20; };
Expand All @@ -25,8 +25,8 @@ describe('gdjs.RuntimeObject', function() {
console.log(benchmarkSuite.run());
});

it('benchmark getAABB of rotated vs non rotated objects, with non default center', function(){
this.timeout(20000);
it('benchmark getAABB of rotated vs non rotated objects, with non default center', function(){
vi.setTimeout(20000);
var object = new gdjs.RuntimeObject(runtimeScene, {name: "obj1", type: "", behaviors: [], effects: []});
object.getWidth = function() { return 10; };
object.getHeight = function() { return 20; };
Expand Down
2 changes: 1 addition & 1 deletion GDJS/tests/benchmarks/spriteruntimeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('gdjs.SpriteRuntimeObject', function () {
});

it('benchmark getAABB of rotated vs non rotated sprite, with custom hitboxes, origin and center', function () {
this.timeout(20000);
vi.setTimeout(20000);
const object = makeSpriteRuntimeObjectWithCustomHitBox(runtimeScene);

const benchmarkSuite = makeBenchmarkSuite({
Expand Down
2 changes: 1 addition & 1 deletion GDJS/tests/benchmarks/variablescontainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('gdjs.VariablesContainer', function() {
it('benchmark get', function() {
this.timeout(20000);
vi.setTimeout(20000);
var container = new gdjs.VariablesContainer();

const benchmarkSuite = makeBenchmarkSuite();
Expand Down
23 changes: 7 additions & 16 deletions GDJS/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
"main": "index.js",
"private": true,
"scripts": {
"test": "karma start --browsers ChromeHeadless --single-run",
"test:watch": "karma start --browsers ChromeHeadless",
"test-benchmark": "karma start --browsers ChromeHeadless --single-run --enableBenchmarks",
"test-benchmark:watch": "karma start --browsers ChromeHeadless --enableBenchmarks",
"test:firefox": "karma start --browsers Firefox --single-run",
"test:firefox:watch": "karma start --browsers Firefox",
"test:chrome": "karma start --browsers Chrome --single-run",
"test:chrome:watch": "karma start --browsers Chrome",
"test:edge": "karma start --browsers EdgeHeadless --single-run",
"test:edge:watch": "karma start --browsers EdgeHeadless"
"test": "vitest run --browser",
"test:watch": "vitest --browser",
"test-benchmark": "vitest run --browser",
"test-benchmark:watch": "vitest --browser"
},
"keywords": [
"HTML5",
Expand All @@ -30,12 +24,9 @@
"mocha": "^1.21.4"
},
"devDependencies": {
"@chiragrupani/karma-chromium-edge-launcher": "2.1.1",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0",
"karma-sinon": "^1.0.5",
"vitest": "^0.34.0",
"vite": "^4.4.9",
"@vitest/browser": "^0.34.0",
"sinon": "^15.0.1"
}
}
2 changes: 1 addition & 1 deletion GDJS/tests/tests/asynctasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
const asyncTasksManager = runtimeScene.getAsyncTasksManager();

this.beforeEach(() => asyncTasksManager.clearTasks());
beforeEach(() => asyncTasksManager.clearTasks());

it('should call a resolved callback', function () {
const cb = createMockCallback();
Expand Down
19 changes: 19 additions & 0 deletions GDJS/tests/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
browser: {
enabled: true,
name: 'chrome',
headless: true,
},
setupFiles: [
'./vitest.setup.js',
'./tests-utils/init.js',
'./tests-utils/init.pixiruntimegamewithassets.js',
'./tests-utils/init.pixiruntimegame.js',
'./tests-utils/MockedCustomObject.js',
],
include: ['tests/**/*.js', 'benchmarks/**/*.js', '../Extensions/**/tests/**/*.js'],
},
});
9 changes: 9 additions & 0 deletions GDJS/tests/vitest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import expect from 'expect.js';
import sinon from 'sinon';

// Expose expect.js and sinon globally like Karma used to do.
// Vitest provides its own expect, but tests rely on expect.js syntax.
// eslint-disable-next-line no-undef
global.expect = expect;
// eslint-disable-next-line no-undef
global.sinon = sinon;