Skip to content

Commit 2652060

Browse files
authored
Merge pull request element-hq#11869 from vector-im/travis/jest
Use Jest for tests
2 parents 044720b + 3fb6b1e commit 2652060

11 files changed

Lines changed: 1501 additions & 859 deletions

File tree

.buildkite/pipeline.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,21 @@ steps:
3636
- docker#v3.0.1:
3737
image: "node:12"
3838

39-
- label: ":karma: Tests"
39+
- label: ":jest: Tests"
4040
agents:
4141
# We use a medium sized instance instead of the normal small ones because
4242
# webpack loves to gorge itself on resources.
4343
queue: "medium"
4444
command:
45-
# Install chrome
46-
- "echo '--- Installing Chrome'"
47-
- "wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -"
48-
- "sh -c 'echo \"deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main\" >> /etc/apt/sources.list.d/google.list'"
49-
- "apt-get update"
50-
- "apt-get install -y google-chrome-stable"
51-
# Run tests
5245
- "echo '--- Fetching Dependencies'"
5346
- "./scripts/fetch-develop.deps.sh --depth 1"
5447
- "yarn install"
48+
- "yarn build:genfiles" # We have to build the app to make sure the autogenned files are present
5549
- "echo '+++ Running Tests'"
5650
- "yarn test"
57-
env:
58-
CHROME_BIN: "/usr/bin/google-chrome-stable"
5951
plugins:
6052
- docker#v3.0.1:
6153
image: "node:10"
62-
propagate-environment: true
6354

6455
- label: ":hammer: Package"
6556
command:

.babelrc renamed to babel.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
module.exports = {
22
"sourceMaps": true,
33
"presets": [
44
["@babel/preset-env", {
@@ -22,4 +22,4 @@
2222
"@babel/plugin-syntax-dynamic-import",
2323
"@babel/plugin-transform-runtime"
2424
]
25-
}
25+
};

karma.conf.js

Lines changed: 0 additions & 171 deletions
This file was deleted.

package.json

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"scripts",
1919
"docs",
2020
"release.sh",
21-
"karma.conf.js",
2221
"deploy",
2322
"CHANGELOG.md",
2423
"CONTRIBUTING.rst",
@@ -57,8 +56,7 @@
5756
"lint:ts": "echo 'We don't actually have a typescript linter at this layer because tslint is being removed from our stack. Presumably your TS is fine.'",
5857
"lint:types": "tsc --noEmit",
5958
"lint:style": "stylelint 'res/css/**/*.scss'",
60-
"test": "yarn build:genfiles && karma start --single-run=true --autoWatch=false --browsers VectorChromeHeadless",
61-
"test:multi": "yarn build:genfiles && karma start"
59+
"test": "jest"
6260
},
6361
"dependencies": {
6462
"browser-request": "^0.3.3",
@@ -99,7 +97,9 @@
9997
"@types/react-dom": "^16.9.4",
10098
"autoprefixer": "^9.7.3",
10199
"babel-eslint": "^10.0.3",
100+
"babel-jest": "^24.9.0",
102101
"babel-loader": "^8.0.6",
102+
"canvas": "^2.6.1",
103103
"chokidar": "^2.0.4",
104104
"concurrently": "^4.0.1",
105105
"cpx": "^1.3.2",
@@ -116,28 +116,20 @@
116116
"eslint-plugin-jest": "^23.0.4",
117117
"eslint-plugin-react": "^7.11.1",
118118
"eslint-plugin-react-hooks": "^2.2.0",
119-
"expect": "^1.16.0",
120119
"extract-text-webpack-plugin": "^4.0.0-beta.0",
120+
"fake-indexeddb": "^3.0.0",
121121
"file-loader": "^5.0.2",
122122
"fs-extra": "^0.30.0",
123123
"html-webpack-plugin": "^3.2.0",
124+
"jest": "^24.9.0",
125+
"jest-environment-jsdom-fourteen": "^1.0.1",
124126
"json-loader": "^0.5.3",
125-
"karma": "^3.1.2",
126-
"karma-chrome-launcher": "^2.2.0",
127-
"karma-cli": "^1.0.1",
128-
"karma-logcapture-reporter": "0.0.1",
129-
"karma-mocha": "^1.3.0",
130-
"karma-sourcemap-loader": "^0.3.7",
131-
"karma-spec-reporter": "0.0.31",
132-
"karma-summary-reporter": "^1.5.1",
133-
"karma-webpack": "4.0.0-beta.0",
134127
"loader-utils": "^1.2.3",
135128
"matrix-mock-request": "^1.2.3",
136129
"matrix-react-test-utils": "^0.2.2",
137130
"mini-css-extract-plugin": "^0.8.0",
138131
"minimist": "^1.2.0",
139132
"mkdirp": "^0.5.1",
140-
"mocha": "^5.2.0",
141133
"optimize-css-assets-webpack-plugin": "^5.0.3",
142134
"postcss-extend": "^1.0.5",
143135
"postcss-import": "^12.0.1",
@@ -198,5 +190,25 @@
198190
"app": "electron_app"
199191
},
200192
"afterSign": "scripts/electron_afterSign.js"
193+
},
194+
"jest": {
195+
"testEnvironment": "jest-environment-jsdom-fourteen",
196+
"testMatch": [
197+
"<rootDir>/test/**/*-test.js"
198+
],
199+
"setupFilesAfterEnv": [
200+
"<rootDir>/node_modules/matrix-react-sdk/test/setupTests.js"
201+
],
202+
"moduleNameMapper": {
203+
"\\.(gif|png|svg|ttf|woff2)$": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/imageMock.js",
204+
"\\$webapp/i18n/languages.json": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/languages.json",
205+
"^browser-request$": "<rootDir>/node_modules/matrix-react-sdk/__mocks__/browser-request.js",
206+
"^react$": "<rootDir>/node_modules/react",
207+
"^react-dom$": "<rootDir>/node_modules/react-dom"
208+
},
209+
"transformIgnorePatterns": [
210+
"/node_modules/(?!matrix-js-sdk).+$",
211+
"/node_modules/(?!matrix-react-sdk).+$"
212+
]
201213
}
202214
}

test/all-tests.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ import WebPlatform from '../../src/vector/platform/WebPlatform';
2121
import * as sdk from "matrix-react-sdk";
2222
import * as jssdk from "matrix-js-sdk";
2323
import "../skin-sdk";
24+
import "../jest-mocks";
2425
import React from "react";
2526
import ReactDOM from "react-dom";
2627
import ReactTestUtils from "react-dom/test-utils";
27-
import expect from "expect";
2828
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
2929
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
3030
import {sleep} from "../test-utils";
3131
import * as test_utils from "../test-utils";
3232
import MockHttpBackend from "matrix-mock-request";
33+
import "fake-indexeddb/auto";
3334

3435

3536
const MatrixChat = sdk.getComponent('structures.MatrixChat');

0 commit comments

Comments
 (0)