Commit 359423fa authored by Julien Enselme's avatar Julien Enselme
Browse files

test: fix tests and running tests

We rely on nps to run jest through its CLI. It will allow us to pass
options to it more easily. We must rely on nps to correctly set an env
var.

We thus deprecate the test command from Aurelia CLI.

We also move Jest configuration into package.json. This was for some
reason required anyway because relying on aurelia.json caused issues
with assets imports.
parent 2ab8fd9f
......@@ -54,8 +54,8 @@ repos:
types: [javascript]
- id: test
name: test
entry: npm
args: [run, test]
entry: yarn
args: [test]
pass_filenames: false
language: system
types: [javascript]
......
......@@ -127,46 +127,6 @@
"output": "dist",
"port": "8282"
},
"testFramework": {
"config": {
"collectCoverageFrom": [
"app/**/*.js",
"!**/*.spec.js",
"!**/node_modules/**",
"!**/test/**"
],
"coverageDirectory": "<rootDir>/test/coverage-jest",
"coverageReporters": [
"json",
"lcov",
"text",
"html"
],
"moduleFileExtensions": [
"js",
"json"
],
"moduleNameMapper": {
"^aurelia-binding$": "<rootDir>/node_modules/aurelia-binding"
},
"modulePaths": [
"<rootDir>/app",
"<rootDir>/node_modules"
],
"setupFiles": [
"<rootDir>/test/jest-pretest.js",
"jest-localstorage-mock"
],
"testEnvironment": "node",
"testRegex": "\\.spec\\.js$",
"transform": {
"^.+\\.(css|less|sass|scss|styl|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "jest-transform-stub",
"^.+\\.js$": "babel-jest"
}
},
"displayName": "Jest",
"id": "jest"
},
"transpiler": {
"displayName": "Babel",
"fileExtension": ".js",
......
import { runCLI } from "@jest/core";
import path from "path";
import project from "../aurelia.json";
import { CLIOptions } from "aurelia-cli";
export default cb => {
let options = project.testFramework.config;
Object.assign(options, {
collectCoverage: CLIOptions.hasFlag("coverage"),
watch: CLIOptions.hasFlag("watch"),
});
if (CLIOptions.getFlagValue("test-path-pattern")) {
Object.assign(options, { testPathPattern: [CLIOptions.getFlagValue("test-path-pattern")] });
}
process.env.BABEL_TARGET = "node";
runCLI(options, [path.resolve(__dirname, "../../")]).then(({ results }) => {
if (results.numFailedTests || results.numFailedTestSuites) {
cb("Tests Failed");
} else {
// For an unknown reason, on gitlab, the test process won't exit. So we help it a little.
if (process.env.CI_SERVER === "yes") {
process.exit(0);
}
cb(null);
}
});
};
{
"description": "Runs Jest and reports the results.",
"flags": [
{
"description": "Watches test files for changes and re-runs the tests automatically.",
"name": "watch",
"type": "boolean"
},
{
"description": "Run only tests matching this pattern",
"name": "test-path-pattern",
"type": "string"
},
{
"description": "Collect coverage",
"name": "coverage",
"type": "boolean"
}
],
"name": "test"
}
const { series, rimraf } = require("nps-utils");
const { crossEnv, series, rimraf } = require("nps-utils");
module.exports = {
scripts: {
......@@ -8,6 +8,11 @@ module.exports = {
config: "au build-config",
manifest: "au build-manifest",
},
test: {
default: crossEnv("BABEL_TARGET=node jest"),
coverage: crossEnv("BABEL_TARGET=node jest --coverage"),
watch: crossEnv("BABEL_TARGET=node jest --watch"),
},
update: {
defaultnames: "au update-external --kind default-names",
translations: series(
......
......@@ -120,6 +120,44 @@
"engines": {
"node": ">=12.14.0"
},
"jest": {
"collectCoverageFrom": [
"app/**/*.js",
"!**/*.spec.js",
"!**/node_modules/**",
"!**/test/**"
],
"coverageDirectory": "<rootDir>/test/coverage-jest",
"coverageReporters": [
"json",
"lcov",
"text",
"html"
],
"moduleFileExtensions": [
"js",
"json"
],
"moduleNameMapper": {
"\\.(css|scss)$": "<rootDir>/test/__mocks__/styleMock.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ogg)$": "<rootDir>/test/__mocks__/fileMock.js",
"^aurelia-binding$": "<rootDir>/node_modules/aurelia-binding"
},
"modulePaths": [
"<rootDir>/app",
"<rootDir>/node_modules"
],
"setupFiles": [
"<rootDir>/test/jest-pretest.js",
"jest-localstorage-mock"
],
"testEnvironment": "node",
"testRegex": "\\.spec\\.js$",
"transform": {
"^.+\\.(css|less|sass|scss|styl|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/__mocks__/fileMock.js",
"^.+\\.js$": "babel-jest"
}
},
"keywords": [
"game",
"board",
......@@ -136,7 +174,7 @@
"build:dev": "nps clean 'build.config --env dev' 'webpack.build --env.environment=dev'",
"lint": "nps lint",
"start": "nps clean 'build.config --env dev' webpack.devserver",
"test": "au test",
"test": "nps test",
"translate": "nps update.translations"
},
"version": "0.5.0"
......
module.exports = "test-file-stub";
module.exports = {};
......@@ -143,7 +143,7 @@ Object {
"deltaMoves": -1,
"description": "Reduce the number of cards a player can play by 1.",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/blizzard-4a67467324.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": true,
"name": "Blizzard",
......@@ -158,7 +158,7 @@ Object {
"deltaDuration": -1,
"description": "Destroy towers and reduce duration for fortress",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/ram-73a6490a4e.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": false,
"name": "Ram",
......@@ -176,7 +176,7 @@ Object {
"cost": 7,
"description": "Prevent the player to move on some colors.",
"duration": 2,
"img": "/dist/assets/game/cards/trumps/fortress-yellow-67a7f343b7.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": true,
"name": "Fortress",
......@@ -191,7 +191,7 @@ Object {
"deltaMoves": 1,
"description": "Allow the player to play one more move.",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/reinforcements-489d9fe1d5.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": false,
"name": "Reinforcements",
......@@ -244,7 +244,7 @@ Object {
"power": Object {
"cost": 8,
"description": "Change the color of a square",
"img": "/dist/assets/game/cards/powers/terraforming-f264420b50.png",
"img": "test-file-stub",
"isPower": true,
"mustTargetPlayer": false,
"name": "Terraforming",
......
......@@ -130,7 +130,7 @@ Object {
"deltaMoves": -1,
"description": "Reduce the number of cards a player can play by 1.",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/blizzard-4a67467324.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": true,
"name": "Blizzard",
......@@ -145,7 +145,7 @@ Object {
"deltaDuration": -1,
"description": "Destroy towers and reduce duration for fortress",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/ram-73a6490a4e.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": false,
"name": "Ram",
......@@ -163,7 +163,7 @@ Object {
"cost": 7,
"description": "Prevent the player to move on some colors.",
"duration": 2,
"img": "/dist/assets/game/cards/trumps/fortress-yellow-67a7f343b7.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": true,
"name": "Fortress",
......@@ -178,7 +178,7 @@ Object {
"deltaMoves": 1,
"description": "Allow the player to play one more move.",
"duration": 1,
"img": "/dist/assets/game/cards/trumps/reinforcements-489d9fe1d5.png",
"img": "test-file-stub",
"isPlayerVisible": true,
"mustTargetPlayer": false,
"name": "Reinforcements",
......@@ -231,7 +231,7 @@ Object {
"power": Object {
"cost": 8,
"description": "Change the color of a square",
"img": "/dist/assets/game/cards/powers/terraforming-f264420b50.png",
"img": "test-file-stub",
"isPower": true,
"mustTargetPlayer": false,
"name": "Terraforming",
......
......@@ -55,10 +55,7 @@ describe("services/notify", () => {
sut._swapFavicon();
expect(document.getElementById).toHaveBeenCalledWith("favicon");
expect(sut._createFavicon).toHaveBeenCalledWith(
expect.stringMatching(/\/dist\/assets\/favicon-notify.*\.png/),
link,
);
expect(sut._createFavicon).toHaveBeenCalledWith("test-file-stub", link);
});
describe("should playCard sound", () => {
......
......@@ -36,7 +36,7 @@ describe("app/services/storage", () => {
sut.saveOptions(options);
expect(localStorage.getItem("options")).toEqual(
expect(localStorage.getItem("last-run-options")).toEqual(
JSON.stringify({
toSave: "toto",
}),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment