From 65473bbbfafda9c59aa2182bec811919706d99ea Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 21 Feb 2024 17:53:32 -0800 Subject: [PATCH] chore: set up ZENSTACK_TEST environment variable during test setup (#1048) --- jest.config.ts | 4 +++- package.json | 4 ++-- packages/plugins/openapi/package.json | 2 +- packages/plugins/swr/package.json | 2 +- packages/plugins/tanstack-query/package.json | 2 +- packages/plugins/trpc/package.json | 2 +- packages/schema/package.json | 2 +- packages/server/package.json | 2 +- script/set-test-env.ts | 1 + test-setup.ts => script/test-global-setup.ts | 2 +- tests/integration/package.json | 2 +- 11 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 script/set-test-env.ts rename test-setup.ts => script/test-global-setup.ts (70%) diff --git a/jest.config.ts b/jest.config.ts index 222e6fb2c..b08a6426f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -9,7 +9,9 @@ export default { // Automatically clear mock calls, instances, contexts and results before every test clearMocks: true, - globalSetup: path.join(__dirname, './test-setup.ts'), + globalSetup: path.join(__dirname, './script/test-global-setup.ts'), + + setupFiles: [path.join(__dirname, './script/set-test-env.ts')], // Indicates whether the coverage information should be collected while executing the test collectCoverage: true, diff --git a/package.json b/package.json index 42168988a..e8409e3bd 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "build": "pnpm -r build", "lint": "pnpm -r lint", - "test": "ZENSTACK_TEST=1 pnpm -r --parallel run test --silent --forceExit", - "test-ci": "ZENSTACK_TEST=1 pnpm -r --parallel run test --silent --forceExit", + "test": "pnpm -r --parallel run test --silent --forceExit", + "test-ci": "pnpm -r --parallel run test --silent --forceExit", "test-scaffold": "tsx script/test-scaffold.ts", "publish-all": "pnpm --filter \"./packages/**\" -r publish --access public", "publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/", diff --git a/packages/plugins/openapi/package.json b/packages/plugins/openapi/package.json index 96a336f58..04508605c 100644 --- a/packages/plugins/openapi/package.json +++ b/packages/plugins/openapi/package.json @@ -17,7 +17,7 @@ "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE dist && copyfiles -u 1 ./src/plugin.zmodel dist && pnpm pack dist --pack-destination '../../../../.build'", "watch": "tsc --watch", "lint": "eslint src --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build" }, "keywords": [ diff --git a/packages/plugins/swr/package.json b/packages/plugins/swr/package.json index c64538378..b4495136d 100644 --- a/packages/plugins/swr/package.json +++ b/packages/plugins/swr/package.json @@ -13,7 +13,7 @@ "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && tsup-node --config ./tsup.config.ts && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'", "watch": "concurrently \"tsc --watch\" \"tsup-node --config ./tsup.config.ts --watch\"", "lint": "eslint src --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build" }, "publishConfig": { diff --git a/packages/plugins/tanstack-query/package.json b/packages/plugins/tanstack-query/package.json index 0c16ca59d..b835479ba 100644 --- a/packages/plugins/tanstack-query/package.json +++ b/packages/plugins/tanstack-query/package.json @@ -69,7 +69,7 @@ "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && tsup-node --config ./tsup.config.ts && tsup-node --config ./tsup-v5.config.ts && node scripts/postbuild && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../../.build'", "watch": "concurrently \"tsc --watch\" \"tsup-node --config ./tsup.config.ts --watch\" \"tsup-node --config ./tsup-v5.config.ts --watch\"", "lint": "eslint src --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build" }, "publishConfig": { diff --git a/packages/plugins/trpc/package.json b/packages/plugins/trpc/package.json index 0b53d2aa2..8d74b6edb 100644 --- a/packages/plugins/trpc/package.json +++ b/packages/plugins/trpc/package.json @@ -13,7 +13,7 @@ "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE 'res/**/*' dist && pnpm pack dist --pack-destination '../../../../.build'", "watch": "tsc --watch", "lint": "eslint src --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build" }, "publishConfig": { diff --git a/packages/schema/package.json b/packages/schema/package.json index 2451a87c8..f83f8121a 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -73,7 +73,7 @@ "bundle": "rimraf bundle && pnpm lint --max-warnings=0 && node build/bundle.js --minify", "watch": "tsc --watch", "lint": "eslint src tests --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build", "postinstall": "node bin/post-install.js" }, diff --git a/packages/server/package.json b/packages/server/package.json index 7ed1e3e29..cbf938ea6 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -9,7 +9,7 @@ "build": "pnpm lint --max-warnings=0 && pnpm clean && tsc && copyfiles ./package.json ./README.md ./LICENSE dist && pnpm pack dist --pack-destination '../../../.build'", "watch": "tsc --watch", "lint": "eslint src --ext ts", - "test": "ZENSTACK_TEST=1 jest", + "test": "jest", "prepublishOnly": "pnpm build" }, "publishConfig": { diff --git a/script/set-test-env.ts b/script/set-test-env.ts new file mode 100644 index 000000000..4db61d8d1 --- /dev/null +++ b/script/set-test-env.ts @@ -0,0 +1 @@ +process.env.ZENSTACK_TEST = '1'; diff --git a/test-setup.ts b/script/test-global-setup.ts similarity index 70% rename from test-setup.ts rename to script/test-global-setup.ts index 9856ff4b5..514cccae7 100644 --- a/test-setup.ts +++ b/script/test-global-setup.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; export default function globalSetup() { - if (!fs.existsSync(path.join(__dirname, '.test/scaffold/package-lock.json'))) { + if (!fs.existsSync(path.join(__dirname, '../.test/scaffold/package-lock.json'))) { console.error(`Test scaffold not found. Please run \`pnpm test-scaffold\` first.`); process.exit(1); } diff --git a/tests/integration/package.json b/tests/integration/package.json index 40627f354..8aed0b6c8 100644 --- a/tests/integration/package.json +++ b/tests/integration/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "lint": "eslint . --ext .ts", - "test": "ZENSTACK_TEST=1 jest" + "test": "jest" }, "keywords": [], "author": "",