Skip to content

Commit

Permalink
Merge pull request #473 from logto-io/gao-upgrade-jest
Browse files Browse the repository at this point in the history
refactor: use rollup and upgrade jest packages
  • Loading branch information
gao-sun authored Apr 20, 2023
2 parents fc73418 + 3a01748 commit e11f6cc
Show file tree
Hide file tree
Showing 42 changed files with 1,043 additions and 1,165 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config: Config.InitialOptions = {
},
],
},
transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto|@silverhand))/)'],
transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@silverhand))/)'],
};

export default config;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
"@commitlint/cli": "^17.0.1",
"@commitlint/config-conventional": "^17.0.0",
"@commitlint/types": "^17.0.0",
"@jest/types": "^27.5.1",
"@jest/types": "^29.5.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@types/node": "^18.15.11",
"husky": "^8.0.1",
"lerna": "^5.0.0",
"rollup": "^3.20.2",
"rollup-plugin-summary": "^2.0.0",
"typescript": "^5.0.0"
},
"workspaces": {
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const { TextDecoder, TextEncoder } = require('text-encoder');
/* eslint-enable unicorn/prefer-module */

/* eslint-disable @silverhand/fp/no-mutation */
global.crypto = {
getRandomValues: (buffer) => crypto.randomFillSync(buffer),
subtle: crypto.webcrypto.subtle,
};
global.crypto.subtle = crypto.webcrypto.subtle;
global.location = location;
global.fetch = fetch;
global.TextDecoder = TextDecoder;
Expand Down
17 changes: 7 additions & 10 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./lib/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/module.mjs"
"import": "./lib/index.mjs"
},
"module": "./lib/module.mjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
"files": [
"lib"
Expand All @@ -22,7 +22,7 @@
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"precommit": "lint-staged",
"check": "tsc --noEmit",
"build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
"lint": "eslint --ext .ts src",
"test": "jest",
"test:coverage": "jest --silent --coverage",
Expand All @@ -34,22 +34,19 @@
"js-base64": "^3.7.4"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@parcel/core": "^2.8.3",
"@parcel/packager-ts": "^2.8.3",
"@parcel/transformer-typescript-types": "^2.8.3",
"@jest/types": "^29.5.0",
"@silverhand/eslint-config": "^2.0.0",
"@silverhand/ts-config": "^1.0.0",
"@swc/core": "^1.3.50",
"@swc/jest": "^0.2.24",
"@types/jest": "^27.5.1",
"@types/jest": "^29.5.0",
"eslint": "^8.38.0",
"jest": "^27.5.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-location-mock": "^1.0.9",
"jest-matcher-specific-error": "^1.0.0",
"lint-staged": "^13.0.0",
"node-fetch": "^2.6.7",
"parcel": "^2.8.3",
"prettier": "^2.8.7",
"text-encoder": "^0.0.4",
"typescript": "^5.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/browser/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../rollup.config.mjs';
6 changes: 6 additions & 0 deletions packages/browser/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig",
"include": [
"src",
]
}
22 changes: 11 additions & 11 deletions packages/browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
]
}
18 changes: 7 additions & 11 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./lib/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/module.mjs"
"import": "./lib/index.mjs"
},
"module": "./lib/module.mjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
"files": [
"lib"
Expand All @@ -22,7 +22,7 @@
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"precommit": "lint-staged",
"check": "tsc --noEmit",
"build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
"lint": "eslint --ext .ts src",
"test": "jest",
"test:coverage": "jest --silent --env=jsdom && jest --silent --coverage",
Expand All @@ -37,24 +37,20 @@
"lodash.once": "^4.1.1"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@parcel/core": "^2.8.3",
"@parcel/packager-ts": "^2.8.3",
"@parcel/transformer-typescript-types": "^2.8.3",
"@jest/types": "^29.5.0",
"@silverhand/eslint-config": "^2.0.0",
"@silverhand/ts-config": "^1.0.0",
"@swc/core": "^1.3.50",
"@swc/jest": "^0.2.24",
"@types/jest": "^27.5.1",
"@types/jest": "^29.5.0",
"@types/lodash.get": "^4.4.6",
"@types/lodash.once": "^4.1.7",
"@types/node": "^18.0.0",
"eslint": "^8.38.0",
"jest": "^27.5.1",
"jest": "^29.5.0",
"jest-matcher-specific-error": "^1.0.0",
"lint-staged": "^13.0.0",
"nock": "^13.1.3",
"parcel": "^2.8.3",
"nock": "^13.3.0",
"prettier": "^2.8.7",
"text-encoder": "^0.0.4",
"type-fest": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/client/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../rollup.config.mjs';
6 changes: 6 additions & 0 deletions packages/client/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig",
"include": [
"src",
]
}
24 changes: 12 additions & 12 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"node",
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"node",
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
]
}
16 changes: 6 additions & 10 deletions packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./lib/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/module.mjs"
"import": "./lib/index.mjs"
},
"module": "./lib/module.mjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
"files": [
"lib"
Expand All @@ -22,7 +22,7 @@
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"precommit": "lint-staged",
"check": "tsc --noEmit",
"build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
"lint": "eslint --ext .ts src",
"test": "jest",
"test:coverage": "jest --silent --coverage",
Expand All @@ -32,10 +32,7 @@
"@logto/node": "^1.1.1"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@parcel/core": "^2.8.3",
"@parcel/packager-ts": "^2.8.3",
"@parcel/transformer-typescript-types": "^2.8.3",
"@jest/types": "^29.5.0",
"@silverhand/eslint-config": "^2.0.0",
"@silverhand/ts-config": "^1.0.0",
"@silverhand/ts-config-react": "^2.0.0",
Expand All @@ -44,17 +41,16 @@
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.13",
"@types/express-session": "^1.17.5",
"@types/jest": "^27.5.1",
"@types/jest": "^29.5.0",
"@types/supertest": "^2.0.12",
"cookie-parser": "^1.4.6",
"eslint": "^8.38.0",
"express": "^4.18.1",
"express-session": "^1.17.3",
"jest": "^27.5.1",
"jest": "^29.5.0",
"jest-location-mock": "^1.0.9",
"jest-matcher-specific-error": "^1.0.0",
"lint-staged": "^13.0.0",
"parcel": "^2.8.3",
"prettier": "^2.8.7",
"supertest": "^6.3.3",
"typescript": "^5.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/express/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../rollup.config.mjs';
6 changes: 6 additions & 0 deletions packages/express/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig",
"include": [
"src",
]
}
22 changes: 11 additions & 11 deletions packages/express/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"extends": "@silverhand/ts-config-react/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
"extends": "@silverhand/ts-config-react/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"types": [
"jest",
"jest-matcher-specific-error"
]
},
"include": [
"src",
"jest.config.ts",
]
}
8 changes: 8 additions & 0 deletions packages/js/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// Need to disable following rules to mock text-decode/text-encoder and crypto for jsdom
// https://github.com/jsdom/jsdom/issues/1612
/* eslint-disable unicorn/prefer-module */
const crypto = require('crypto');

const { TextDecoder, TextEncoder } = require('text-encoder');
/* eslint-enable unicorn/prefer-module */

/* eslint-disable @silverhand/fp/no-mutation */
// Mock WebCrypto in JSDOM
if (global.window !== undefined) {
global.CryptoKey = crypto.webcrypto.CryptoKey;
global.crypto.subtle = crypto.webcrypto.subtle;
}

global.TextDecoder = TextDecoder;
global.TextEncoder = TextEncoder;
/* eslint-enable @silverhand/fp/no-mutation */
20 changes: 9 additions & 11 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "./lib/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/module.mjs"
"import": "./lib/index.mjs"
},
"module": "./lib/module.mjs",
"module": "./lib/index.mjs",
"types": "./lib/index.d.ts",
"files": [
"lib"
Expand All @@ -22,7 +22,7 @@
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"precommit": "lint-staged",
"check": "tsc --noEmit",
"build": "rm -rf lib/ && pnpm check && parcel build && cp lib/index.d.ts lib/module.d.mts",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
"lint": "eslint --ext .ts src",
"test": "jest",
"test:coverage": "jest --silent --env=jsdom && jest --silent",
Expand All @@ -35,24 +35,22 @@
"lodash.get": "^4.4.2"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@parcel/core": "^2.8.3",
"@parcel/packager-ts": "^2.8.3",
"@parcel/transformer-typescript-types": "^2.8.3",
"@jest/types": "^29.5.0",
"@silverhand/eslint-config": "^2.0.0",
"@silverhand/ts-config": "^1.0.0",
"@swc/core": "^1.3.50",
"@swc/jest": "^0.2.24",
"@types/jest": "^27.5.1",
"@types/jest": "^29.5.0",
"@types/lodash.get": "^4.4.6",
"@types/node": "^18.0.0",
"eslint": "^8.38.0",
"jest": "^27.5.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-matcher-specific-error": "^1.0.0",
"lint-staged": "^13.0.0",
"nock": "^13.1.3",
"parcel": "^2.8.3",
"nock": "^13.3.0",
"prettier": "^2.8.7",
"rollup": "^3.20.2",
"text-encoder": "^0.0.4",
"type-fest": "^3.0.0",
"typescript": "^5.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/js/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '../../rollup.config.mjs';
Loading

0 comments on commit e11f6cc

Please sign in to comment.