Skip to content

Commit

Permalink
E Updates jest, ts-jest dependency and integrates @swc/jest and mocks…
Browse files Browse the repository at this point in the history
… transport module

- configuration and transport (Client) have a cyclical module dependency through their index.ts => inner chains
- configuration, transport and services (Server) have multiple cyclical dependencies through their index.ts => inner chains
  • Loading branch information
dreamora committed Nov 14, 2022
1 parent 9547cbc commit 59e6f5c
Show file tree
Hide file tree
Showing 25 changed files with 1,195 additions and 782 deletions.
25 changes: 17 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ module.exports = {
collectCoverageFrom: ["**/*.{ts,tsx}"],
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["index.ts", "test/*"],
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"@quatico/magellan-shared": "<rootDir>/packages/shared/src",
Expand All @@ -22,10 +17,24 @@ module.exports = {
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testRegex: ".*spec\\.(jsx?|tsx?)$",
testURL: "http://localhost/",
testEnvironmentOptions: { url: "http://localhost/" },
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest",
"^.+\\.(js|jsx|ts|tsx)$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
},
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
},
resetMocks: true,
watchman: false
watchman: false,
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"license:remove": "license-check-and-add remove -f license-config.json"
},
"devDependencies": {
"@swc/core": "^1.3.16",
"@swc/jest": "^0.2.23",
"cross-env": "^7.0.3",
"eslint": "^7.22.0",
"eslint-config-prettier": "^7.2.0",
Expand All @@ -57,6 +59,7 @@
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-testing-library": "^3.9.2",
"husky": "^8.0.0",
"jest":"^29.3.1",
"lerna": "~6.0.1",
"license-check-and-add": "^4.0.5",
"lint-staged": "^13.0.3",
Expand All @@ -65,6 +68,7 @@
"prettier": "1.19.1",
"regenerator-runtime": "0.13.7",
"rimraf": "3.0.2",
"ts-jest": "^29.0.3",
"typescript": "~4.7.4"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe("createClientTransformer", () => {
const actual = printer.printFile(transformed.transformed[0]);

expect(actual).toMatchInlineSnapshot(`
"import { remoteInvoke } from \\"@quatico/magellan-client\\";
// @service({\\"target\\":\\"expected\\"})
"import { remoteInvoke } from "@quatico/magellan-client";
// @service({"target":"expected"})
export const getDate = async () => {
return remoteInvoke({ name: \\"getDate\\", data: {}, namespace: \\"default\\" });
return remoteInvoke({ name: "getDate", data: {}, namespace: "default" });
};
"
`);
Expand All @@ -39,10 +39,10 @@ describe("createClientTransformer", () => {
const actual = printer.printFile(transformed.transformed[0]);

expect(actual).toMatchInlineSnapshot(`
"import { remoteInvoke } from \\"@quatico/magellan-client\\";
"import { remoteInvoke } from "@quatico/magellan-client";
// @service()
export const getDate = async () => {
return remoteInvoke({ name: \\"getDate\\", data: {}, namespace: \\"default\\" });
return remoteInvoke({ name: "getDate", data: {}, namespace: "default" });
};
"
`);
Expand Down
23 changes: 16 additions & 7 deletions packages/addons/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ module.exports = {
collectCoverageFrom: ["./src/**/*.ts"],
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["index.ts"],
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
moduleFileExtensions: ["ts", "js", "json", "node"],
moduleNameMapper: {
"@quatico/magellan-client": "<rootDir>/../client/src",
"@quatico/magellan-server": "<rootDir>/../server/src",
},
testRegex: "(src|addons)/.*\\.spec\\.(js|ts)$",
setupFilesAfterEnv: ["<rootDir>/../../jest.setup.ts"],
testURL: "http://localhost/",
testEnvironmentOptions: { url: "http://localhost/" },
transform: {
"^.+\\.(js|ts)$": "ts-jest",
"^.+\\.(js|ts)$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
},
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
},
resetMocks: true,
};
8 changes: 5 additions & 3 deletions packages/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"publish-npm": "npm publish --access public"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@swc/core": "^1.3.16",
"@swc/jest": "^0.2.23",
"@types/jest": "^29.2.2",
"@types/node": "16",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
Expand All @@ -46,10 +48,10 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-testing-library": "^5.2.0",
"husky": "7.0.4",
"jest": "27.5.1",
"jest": "^29.3.1",
"prettier": "^2.6.2",
"rimraf": "3.0.2",
"ts-jest": "27.1.4"
"ts-jest": "^29.0.3"
},
"dependencies": {
"@quatico/magellan-client": "^0.1.4",
Expand Down
23 changes: 16 additions & 7 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ module.exports = {
collectCoverageFrom: ["./src/**/*.{ts,tsx}"],
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["index.ts"],
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"@quatico/magellan-shared": "<rootDir>/../shared/src",
Expand All @@ -22,9 +17,23 @@ module.exports = {
},
testRegex: "src/.*spec\\.(jsx?|tsx?)$",
setupFilesAfterEnv: ["<rootDir>/../../jest.setup.ts"],
testURL: "http://localhost/",
testEnvironmentOptions: { url: "http://localhost/" },
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest",
"^.+\\.(js|jsx|ts|tsx)$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
},
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
},
resetMocks: true,
};
7 changes: 5 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"ts-node": "10.7.0"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@swc/core": "^1.3.16",
"@swc/jest": "^0.2.23",
"@types/jest": "^29.2.2",
"@types/node": "16",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
Expand All @@ -62,10 +64,11 @@
"eslint-plugin-jest": "^24.3.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-testing-library": "^3.9.2",
"jest": "^27.3.1",
"jest": "^29.3.1",
"minimist": "1.2.6",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "~4.7.4"
},
"engines": {
Expand Down
23 changes: 16 additions & 7 deletions packages/client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,30 @@ module.exports = {
collectCoverageFrom: ["./src/**/*.{ts,tsx}"],
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["index.ts"],
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"@quatico/magellan-shared": "<rootDir>/../shared/src",
},
testEnvironment: "jsdom",
testRegex: "src/.*spec\\.(jsx?|tsx?)$",
setupFilesAfterEnv: ["<rootDir>/../../jest.setup.ts"],
testURL: "http://localhost/",
testEnvironmentOptions: { url: "http://localhost/" },
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest",
"^.+\\.(j|t)sx?$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
},
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
},
resetMocks: true,
};
8 changes: 6 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"@quatico/magellan-shared": "^0.1.4"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@swc/core": "^1.3.16",
"@swc/jest": "^0.2.23",
"@types/jest": "^29.2.2",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.22.0",
Expand All @@ -47,9 +49,11 @@
"eslint-plugin-jest": "^24.3.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-testing-library": "^3.9.2",
"jest": "^27.3.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"typescript": "~4.7.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/
import { formdataFetch } from "../transport";
import { expandConfig, getConfiguration, initProjectConfiguration } from "./configuration-repository";
import { getDefaultConfiguration } from "./default-configuration";

jest.mock("../transport", () => ({
formdataFetch: jest.fn(),
}));

import { formdataFetch } from "../transport";

beforeEach(() => {
// @ts-ignore
global.__qsMagellanConfig__ = undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/transport/formdata-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* ---------------------------------------------------------------------------------------------
*/
import { TransportFunction, TransportHandler } from "@quatico/magellan-shared";
import { Context } from "../configuration";
import type { Context } from "../configuration";

export const formdataFetch: TransportHandler = async (func: TransportFunction, ctx: Context): Promise<string> => {
const { name, payload, namespace, endpoint } = func;
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/
export {transportRequest} from "./transport-request";
export {formdataFetch} from "./formdata-fetch";
export { transportRequest } from "./transport-request";
export { formdataFetch } from "./formdata-fetch";
17 changes: 9 additions & 8 deletions packages/client/src/transport/transport-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
* ---------------------------------------------------------------------------------------------
*/
import {Context, resolveNamespace} from "../configuration";
import {deserialize, packInput, RemoteFunction, Serialization} from "@quatico/magellan-shared";
import type { Context } from "../configuration";
import { resolveNamespace } from "../configuration";
import { deserialize, packInput, RemoteFunction, Serialization } from "@quatico/magellan-shared";

export const transportRequest = async <O>(
func: RemoteFunction,
ctx: Context = {headers: new Headers()},
serialization: Serialization = {serialize: packInput, deserialize}
ctx: Context = { headers: new Headers() },
serialization: Serialization = { serialize: packInput, deserialize }
): Promise<O> => {
const {name, data = {}, namespace = "default"} = func;
const { name, data = {}, namespace = "default" } = func;

if (!name) {
throw new Error('Cannot invoke remote function without "name" property.');
Expand All @@ -25,13 +26,13 @@ export const transportRequest = async <O>(
throw new Error(`Cannot serialize input parameter for remote function: "${name}".`);
}

const {endpoint, transport} = resolveNamespace(namespace);
const { endpoint, transport } = resolveNamespace(namespace);

const result = await transport({name, payload, namespace, endpoint}, ctx);
const result = await transport({ name, payload, namespace, endpoint }, ctx);

try {
return serialization.deserialize(result);
} catch (err) {
throw new Error(`Cannot deserialize response from remote function: "${name}".`);
}
};
};
21 changes: 15 additions & 6 deletions packages/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ module.exports = {
collectCoverageFrom: ["./src/**/*.{ts,tsx}"],
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["index.ts"],
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
moduleNameMapper: {
"@quatico/magellan-shared": "<rootDir>/../shared/src",
Expand All @@ -24,7 +19,21 @@ module.exports = {
testRegex: "src/.*spec\\.(jsx?|tsx?)$",
setupFilesAfterEnv: ["<rootDir>/../../jest.setup.ts"],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest",
"^.+\\.(j|t)sx?$": [
"@swc/jest",
{
jsc: {
parser: {
syntax: "typescript",
},
transform: {
react: {
runtime: "automatic",
},
},
},
},
],
},
resetMocks: true,
};
Loading

0 comments on commit 59e6f5c

Please sign in to comment.