Skip to content
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

chore: remove karma + jasmine and replace with jest globally #4546

Merged
merged 21 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3dcbc60
chore: cherry-pick
aweiss-dev Oct 20, 2022
61f21c6
feat: remove jasmine/karma and use jest
aweiss-dev Oct 20, 2022
2ceec1c
chore: remove jasmine from store-engines
aweiss-dev Oct 20, 2022
77d39b4
chore: remove jasmine + karma globally
aweiss-dev Oct 21, 2022
a332552
chore: install dependencies in root
aweiss-dev Oct 21, 2022
28a21e1
fix: exlude d.ts files from linting
aweiss-dev Oct 21, 2022
b082df0
Merge remote-tracking branch 'origin' into chore/remove_karma_jasmine
aweiss-dev Oct 21, 2022
526a231
Merge remote-tracking branch 'origin' into chore/remove_karma_jasmine
aweiss-dev Oct 21, 2022
e9aaad4
feat: replace ts-jest with @swc/jest and remove coverage to speed up …
aweiss-dev Oct 21, 2022
e0ebcc7
chore: remove last coverage
aweiss-dev Oct 21, 2022
8c95766
Merge remote-tracking branch 'origin' into chore/remove_karma_jasmine
aweiss-dev Oct 21, 2022
04ef1cb
feat: add a jest config root and hoist npm dependencies into root
aweiss-dev Oct 21, 2022
91b73db
chore: remove duplicated copyright
aweiss-dev Oct 21, 2022
2cb45c3
chore: copyright
aweiss-dev Oct 21, 2022
4bae450
fix: install jest only in root and call it from workspaces
aweiss-dev Oct 22, 2022
87db674
fix: throw errors in tests
aweiss-dev Oct 22, 2022
3623d7a
fix: package without tests didnt need jest as execution
aweiss-dev Oct 22, 2022
6beb0a6
chore: remove not necessary settings from jest, have every package ma…
aweiss-dev Oct 24, 2022
89f7f85
Merge remote-tracking branch 'origin' into chore/remove_karma_jasmine
aweiss-dev Oct 24, 2022
ee47ff2
fix: add snapshotSerializer back in
aweiss-dev Oct 24, 2022
5ef3987
fix: use node test environment for copy-config
aweiss-dev Oct 24, 2022
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 .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"env": {
"jasmine": true,
"jest/globals": true
},
"extends": ["./packages/eslint-config/eslintrc.js", "plugin:jest/recommended"],
"ignorePatterns": ["*config.js", "demo/", "bin/", "eslint*", "webpack*", "*.js"],
"ignorePatterns": ["*config.js", "demo/", "bin/", "eslint*", "webpack*", "*.js", "*.d.ts"],
"globals": {
"NodeJS": "readonly"
},
Expand Down Expand Up @@ -32,7 +31,7 @@
"no-dupe-class-members": "off",
"no-magic-numbers": "off",
"valid-jsdoc": "off",
"jest/no-jasmine-globals": "off",
"jest/no-jasmine-globals": "error",
"jest/no-identical-title": "warn",
"jest/no-done-callback": "warn",
"jest/no-disabled-tests": "warn",
Expand Down
1 change: 0 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
nmHoistingLimits: workspaces

nodeLinker: node-modules

plugins:
Expand Down
26 changes: 26 additions & 0 deletions jest.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Wire
* Copyright (C) 2022 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
module.exports = {
clearMocks: true,
testMatch: ["**/?(*.)+(spec|test).+(ts|tsx)", "test/**/*.+(ts|tsx)",],
transform: {
"^.+\\.(ts|tsx)$": "@swc/jest"
},
testEnvironment: "jsdom",
}
13 changes: 8 additions & 5 deletions packages/store-engine-dexie/babel.config.js → jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
*
*/

const baseConfig = require('./jest.config.base')

module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-optional-chaining',
...baseConfig,
projects: ['<rootDir>/packages/*/jest.config.js'],
coverageDirectory: '<rootDir>/coverage/',
collectCoverageFrom: [
'<rootDir>/packages/*/src/**/*.{ts,tsx}',
],
presets: ['@babel/preset-typescript'],
};

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"devDependencies": {
"@babel/eslint-parser": "7.19.1",
"@babel/core": "^7.19.6",
"@babel/eslint-parser": "^7.19.1",
"@lerna-lite/changed": "^1.11.3",
"@lerna-lite/cli": "^1.11.3",
"@lerna-lite/run": "^1.11.3",
"@swc/core": "^1.3.10",
"@swc/jest": "^0.2.23",
"@types/babel__core": "^7",
"@types/jest": "^29.2.0",
"@types/node": "^18.11.3",
"@types/rimraf": "3.0.2",
"@typescript-eslint/eslint-plugin": "5.40.1",
"@typescript-eslint/parser": "5.40.1",
Expand All @@ -21,7 +27,8 @@
"eslint-plugin-simple-import-sort": "8.0.0",
"eslint-plugin-unused-imports": "2.0.0",
"husky": "8.0.1",
"jest": "^29.0.3",
"jest": "^29.2.1",
"jest-environment-jsdom": "^29.2.1",
"lint-staged": "13.0.3",
"prettier": "2.7.1",
"rimraf": "3.0.2",
Expand Down Expand Up @@ -57,6 +64,7 @@
"release": "yarn new-version && yarn new-publish",
"test": "lerna run build --include-dependencies --since && lerna run test --since",
"test:all": "lerna run build && lerna run test",
"test:coverage": "lerna run test:coverage",
"prepare": "husky install"
},
"workspaces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
*
*/

const baseConfig = require('../../jest.config.base');

module.exports = {
clearMocks: true,
testMatch: ['**/?(*.)+(spec|test).+(ts|tsx)', 'test/**/*.+(ts|tsx)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
...baseConfig,
testEnvironment: 'node',
};
15 changes: 8 additions & 7 deletions packages/api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
"@babel/preset-env": "^7.19.1",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.18.6",
"@swc/core": "^1.3.10",
"@swc/jest": "^0.2.23",
"@types/axios": "^0.14.0",
"@types/babel__preset-env": "^7",
"@types/jest": "^29.0.3",
"@types/node": "^18.11.2",
"@types/rimraf": "^3",
"@types/jest": "^29.2.0",
"@types/node": "^18.11.4",
"@types/spark-md5": "3.0.2",
"@types/tough-cookie": "4.0.1",
"@types/ws": "8.5.3",
Expand All @@ -37,17 +38,16 @@
"concurrently": "7.5.0",
"cross-env": "7.0.3",
"dotenv": "16.0.3",
"jest": "^29.0.3",
"jest-environment-jsdom": "^29.2.1",
"jest": "^29.2.1",
"nock": "13.2.9",
"nyc": "15.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"rimraf": "^3.0.2",
"sinon": "14.0.1",
"sinon-har-server": "0.3.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"ws": "8.9.0"
},
"description": "Wire API Client to send and receive data.",
Expand All @@ -70,6 +70,7 @@
"start": "concurrently \"tsc -w\" \"webpack -w\" \"browser-sync start -c bs-config.js\"",
"start:node": "cross-env NODE_DEBUG='@wireapp*' node --inspect -r ts-node/register demo.ts",
"test": "jest",
"test:coverage": "jest --coverage",
"watch": "webpack serve --config webpack.browser.js",
"prepare": "yarn dist"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/api-client/src/http/HttpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('HttpClient', () => {

try {
await client._sendRequest({method: 'GET', baseURL: testConfig.urls.rest, url: AuthAPI.URL.ACCESS});
fail();
aweiss-dev marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Should not resolve');
} catch (error) {
expect((error as BackendError).message).toBe('Authentication failed because the token is invalid.');
}
Expand All @@ -92,7 +92,7 @@ describe('HttpClient', () => {

try {
await client._sendRequest({method: 'GET', baseURL: testConfig.urls.rest, url: AuthAPI.URL.ACCESS});
fail();
aweiss-dev marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Should not resolve');
} catch (error) {
expect((error as BackendError).message).toBe('Authentication failed because the cookie is missing.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"outDir": "src",
"rootDir": "src"
},
"exclude": ["jest.config.ts", "node_modules", "demo.ts"],
"exclude": ["jest.config.js", "node_modules", "demo.ts"],
"extends": "../../tsconfig.json"
}
4 changes: 2 additions & 2 deletions packages/archive/bot-api/src/Bot.test.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('Bot', () => {

const bot2 = new Bot(credentials, config);

expect(bot['config']).not.toEqual(jasmine.objectContaining(config));
expect(bot2['config']).toEqual(jasmine.objectContaining(config));
expect(bot['config']).not.toEqual(expect.objectContaining(config));
expect(bot2['config']).toEqual(expect.objectContaining(config));
});
});
});
60 changes: 31 additions & 29 deletions packages/archive/bot-api/src/MessageHandler.test.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,24 @@ describe('MessageHandler', () => {
await mainHandler.account!.initServices({userId: 'user-id', clientType: ClientType.NONE});
await mainHandler.account!['apiClient']['createContext']('user-id', ClientType.NONE);

spyOn(mainHandler.account!.service!.conversation, 'send').and.returnValue(
Promise.resolve({state: PayloadBundleState.OUTGOING_SENT, sentAt: new Date().toISOString(), id: createId()}),
);
jest
.spyOn(mainHandler.account!.service!.conversation, 'send')
.and.returnValue(
Promise.resolve({state: PayloadBundleState.OUTGOING_SENT, sentAt: new Date().toISOString(), id: createId()}),
);
});

describe('sendConnectionResponse', () => {
it('sends the correct data when accepting the connection', async () => {
const userId = UUID.genV4().toString();
const acceptConnection = true;

spyOn(mainHandler.account!.service!.connection, 'acceptConnection').and.returnValue(
Promise.resolve({} as Connection),
);
spyOn(mainHandler.account!.service!.connection, 'ignoreConnection').and.returnValue(
Promise.resolve({} as Connection),
);
jest
.spyOn(mainHandler.account!.service!.connection, 'acceptConnection')
.and.returnValue(Promise.resolve({} as Connection));
jest
.spyOn(mainHandler.account!.service!.connection, 'ignoreConnection')
.and.returnValue(Promise.resolve({} as Connection));

await mainHandler.sendConnectionResponse(userId, acceptConnection);
expect(mainHandler.account!.service!.connection.acceptConnection).toHaveBeenCalledWith(userId);
Expand All @@ -71,12 +73,12 @@ describe('MessageHandler', () => {
const userId = UUID.genV4().toString();
const acceptConnection = false;

spyOn(mainHandler.account!.service!.connection, 'acceptConnection').and.returnValue(
Promise.resolve({} as Connection),
);
spyOn(mainHandler.account!.service!.connection, 'ignoreConnection').and.returnValue(
Promise.resolve({} as Connection),
);
jest
.spyOn(mainHandler.account!.service!.connection, 'acceptConnection')
.and.returnValue(Promise.resolve({} as Connection));
jest
.spyOn(mainHandler.account!.service!.connection, 'ignoreConnection')
.and.returnValue(Promise.resolve({} as Connection));

await mainHandler.sendConnectionResponse(userId, acceptConnection);
expect(mainHandler.account!.service!.connection.ignoreConnection).toHaveBeenCalledWith(userId);
Expand All @@ -96,18 +98,18 @@ describe('MessageHandler', () => {
},
];

spyOn(MessageBuilder, 'buildTextMessage').and.callThrough();
jest.spyOn(MessageBuilder, 'buildTextMessage');

await mainHandler.sendText(conversationId, messageText, mentionData);

expect(MessageBuilder.buildTextMessage).toHaveBeenCalledWith({
text: messageText,
});
expect(mainHandler.account!.service!.conversation.send).toHaveBeenCalledWith(
jasmine.objectContaining({
expect.objectContaining({
protocol: ConversationProtocol.PROTEUS,
payload: jasmine.objectContaining({
content: jasmine.objectContaining({mentions: mentionData, text: messageText}),
payload: expect.objectContaining({
content: expect.objectContaining({mentions: mentionData, text: messageText}),
}),
}),
);
Expand All @@ -117,17 +119,17 @@ describe('MessageHandler', () => {
const conversationId = UUID.genV4().toString();
const message = UUID.genV4().toString();

spyOn(MessageBuilder, 'buildTextMessage').and.callThrough();
jest.spyOn(MessageBuilder, 'buildTextMessage');

await mainHandler.sendText(conversationId, message);

expect(MessageBuilder.buildTextMessage).toHaveBeenCalledWith({
text: message,
});
expect(mainHandler.account!.service!.conversation.send).toHaveBeenCalledWith(
jasmine.objectContaining({
expect.objectContaining({
protocol: ConversationProtocol.PROTEUS,
payload: jasmine.objectContaining({content: jasmine.objectContaining({text: message})}),
payload: expect.objectContaining({content: expect.objectContaining({text: message})}),
}),
);
});
Expand All @@ -137,17 +139,17 @@ describe('MessageHandler', () => {
const message = UUID.genV4().toString();
const userIds = [UUID.genV4().toString(), UUID.genV4().toString()];

spyOn(MessageBuilder, 'buildTextMessage').and.callThrough();
jest.spyOn(MessageBuilder, 'buildTextMessage');

await mainHandler.sendText(conversationId, message, undefined, undefined, userIds);

expect(MessageBuilder.buildTextMessage).toHaveBeenCalledWith({
text: message,
});
expect(mainHandler.account!.service!.conversation.send).toHaveBeenCalledWith(
jasmine.objectContaining({
expect.objectContaining({
protocol: ConversationProtocol.PROTEUS,
payload: jasmine.objectContaining({content: jasmine.objectContaining({text: message})}),
payload: expect.objectContaining({content: expect.objectContaining({text: message})}),
userIds,
}),
);
Expand All @@ -158,8 +160,8 @@ describe('MessageHandler', () => {
it('sends the correct data when typing started', async () => {
const conversationId = UUID.genV4().toString();

spyOn(mainHandler.account!.service!.conversation, 'sendTypingStart').and.returnValue(Promise.resolve());
spyOn(mainHandler.account!.service!.conversation, 'sendTypingStop').and.returnValue(Promise.resolve());
jest.spyOn(mainHandler.account!.service!.conversation, 'sendTypingStart').mockReturnValue(Promise.resolve());
jest.spyOn(mainHandler.account!.service!.conversation, 'sendTypingStop').mockReturnValue(Promise.resolve());

await mainHandler.sendTyping(conversationId, CONVERSATION_TYPING.STARTED);

Expand All @@ -170,8 +172,8 @@ describe('MessageHandler', () => {
it('sends the correct data when typing stopped', async () => {
const conversationId = UUID.genV4().toString();

spyOn(mainHandler.account!.service!.conversation, 'sendTypingStart').and.returnValue(Promise.resolve());
spyOn(mainHandler.account!.service!.conversation, 'sendTypingStop').and.returnValue(Promise.resolve());
jest.spyOn(mainHandler.account!.service!.conversation, 'sendTypingStart').mockReturnValue(Promise.resolve());
jest.spyOn(mainHandler.account!.service!.conversation, 'sendTypingStop').mockReturnValue(Promise.resolve());

await mainHandler.sendTyping(conversationId, CONVERSATION_TYPING.STOPPED);

Expand Down
6 changes: 3 additions & 3 deletions packages/archive/store-engine-sqleet/src/SQLeetEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('SQLeetEngine', () => {
try {
const entity = {'name\'"`': 'Otto'};
await engine.create('users', '1', entity);
fail();
aweiss-dev marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Method is supposed to throw an error.');
} catch (error) {
expect(error.message).toBe(
'Entity is empty for table "users". Are you sure you set the right scheme / column names?',
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('SQLeetEngine', () => {

try {
await engine.updateOrCreate('ffff', '1', {name: 'Otto'});
fail();
throw new Error('Method is supposed to throw an error.');
} catch (error) {
expect(error.message).toBe('Table "ffff" does not exist.');
}
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('SQLeetEngine', () => {

try {
await engine.export();
fail();
throw new Error('Method is supposed to throw an error.');
} catch (error) {
expect(error.message).toBe('Database closed');
}
Expand Down
6 changes: 0 additions & 6 deletions packages/bazinga64/jasmine.json

This file was deleted.

Loading