mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-14 00:19:16 +01:00
## About the changes
Based on the first hypothesis from
https://github.com/Unleash/unleash/pull/9264, I decided to find an
alternative way of initializing the DB, mainly trying to run migrations
only once and removing that from the actual test run.
I found in [Postgres template
databases](https://www.postgresql.org/docs/current/manage-ag-templatedbs.html)
an interesting option in combination with jest global initializer.
### Changes on how we use DBs for testing
Previously, we were relying on a single DB with multiple schemas to
isolate tests, but each schema was empty and required migrations or
custom DB initialization scripts.
With this method, we don't need to use different schema names
(apparently there's no templating for schemas), and we can use new
databases. We can also eliminate custom initialization code.
### Legacy tests
This method also highlighted some wrong assumptions in existing tests.
One example is the existence of `default` environment, that because of
being deprecated is no longer available, but because tests are creating
the expected db state manually, they were not updated to match the
existing db state.
To keep tests running green, I've added a configuration to use the
`legacy` test setup (24 tests). By migrating these, we'll speed up
tests, but the code of these tests has to be modified, so I leave this
for another PR.
## Downsides
1. The template db initialization happens at the beginning of any test,
so local development may suffer from slower unit tests. As a workaround
we could define an environment variable to disable the db migration
2. Proliferation of test dbs. In ephemeral environments, this is not a
problem, but for local development we should clean up from time to time.
There's the possibility of cleaning up test dbs using the db name as a
pattern:
2ed2e1c274/scripts/jest-setup.ts (L13-L18)
but I didn't want to add this code yet. Opinions?
## Benefits
1. It allows us migrate only once and still get the benefits of having a
well known state for tests.
3. It removes some of the custom setup for tests (which in some cases
ends up testing something not realistic)
4. It removes the need of testing migrations:
https://github.com/Unleash/unleash/blob/main/src/test/e2e/migrator.e2e.test.ts
as migrations are run at the start
5. Forces us to keep old tests up to date when we modify our database
256 lines
8.4 KiB
JSON
256 lines
8.4 KiB
JSON
{
|
||
"name": "unleash-server",
|
||
"description": "Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.",
|
||
"version": "6.7.0",
|
||
"keywords": [
|
||
"unleash",
|
||
"feature flag",
|
||
"flag",
|
||
"feature toggle",
|
||
"feature",
|
||
"toggle"
|
||
],
|
||
"files": [
|
||
"dist",
|
||
"docs",
|
||
"frontend/build",
|
||
"frontend/build/*",
|
||
"frontend/build/**/*",
|
||
"frontend/index.js",
|
||
"frontend/package.json"
|
||
],
|
||
"repository": {
|
||
"type": "git",
|
||
"url": "ssh://git@github.com:unleash/unleash.git"
|
||
},
|
||
"bugs": {
|
||
"url": "https://github.com/unleash/unleash/issues"
|
||
},
|
||
"types": "./dist/lib/server-impl.d.ts",
|
||
"engines": {
|
||
"node": ">=18 <21"
|
||
},
|
||
"license": "Apache-2.0",
|
||
"main": "./dist/lib/server-impl.js",
|
||
"scripts": {
|
||
"start": "TZ=UTC node ./dist/server.js",
|
||
"copy-templates": "copyfiles -u 1 src/mailtemplates/**/* dist/",
|
||
"build:backend": "tsc --pretty --strictNullChecks false",
|
||
"build:frontend": "yarn --cwd ./frontend run build",
|
||
"build:frontend:if-needed": "./scripts/build-frontend-if-needed.sh",
|
||
"build": "yarn run clean && concurrently \"yarn:copy-templates\" \"yarn:build:frontend\" \"yarn:build:backend\"",
|
||
"dev:backend": "TZ=UTC NODE_ENV=development tsc-watch --strictNullChecks false --onSuccess \"node dist/server-dev.js\"",
|
||
"dev:frontend": "wait-on tcp:4242 && yarn --cwd ./frontend run dev",
|
||
"dev:frontend:cloud": "UNLEASH_BASE_PATH=/demo/ yarn run dev:frontend",
|
||
"dev": "concurrently \"yarn:dev:backend\" \"yarn:dev:frontend\"",
|
||
"prepare:backend": "concurrently \"yarn:copy-templates\" \"yarn:build:backend\"",
|
||
"start:dev": "yarn run clean && TZ=UTC NODE_ENV=development tsc-watch --strictNullChecks false --onSuccess \"node dist/server-dev.js\"",
|
||
"db-migrate": "db-migrate --migrations-dir ./src/migrations",
|
||
"lint": "biome check .",
|
||
"lint:fix": "biome check . --write",
|
||
"local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build",
|
||
"build:watch": "yarn run clean && tsc -w --strictNullChecks false",
|
||
"prepare": "husky && yarn --cwd ./frontend install && if [ ! -d ./dist ]; then yarn build; fi",
|
||
"test": "NODE_ENV=test PORT=4243 node --trace-warnings node_modules/.bin/jest",
|
||
"test:unit": "NODE_ENV=test PORT=4243 jest --testPathIgnorePatterns=src/test/e2e --testPathIgnorePatterns=dist",
|
||
"test:docker": "./scripts/docker-postgres.sh",
|
||
"test:report": "NODE_ENV=test PORT=4243 jest --reporters=\"default\" --reporters=\"jest-junit\"",
|
||
"test:docker:cleanup": "docker rm -f unleash-postgres",
|
||
"test:watch": "yarn test --watch",
|
||
"test:coverage": "NODE_ENV=test PORT=4243 jest --coverage --testLocationInResults --outputFile=\"coverage/report.json\" --forceExit",
|
||
"test:coverage:jest": "NODE_ENV=test PORT=4243 jest --silent --ci --json --coverage --testLocationInResults --outputFile=\"report.json\" --forceExit",
|
||
"test:updateSnapshot": "NODE_ENV=test PORT=4243 jest --updateSnapshot",
|
||
"seed:setup": "ts-node --compilerOptions '{\"strictNullChecks\": false}' src/test/e2e/seed/segment.seed.ts",
|
||
"seed:serve": "UNLEASH_DATABASE_NAME=unleash_test UNLEASH_DATABASE_SCHEMA=seed yarn run start:dev",
|
||
"clean": "del-cli --force dist",
|
||
"heroku-postbuild": "cd frontend && yarn && yarn build",
|
||
"prepack": "./scripts/prepack.sh",
|
||
"schema:update": "node ./.husky/update-openapi-spec-list.js"
|
||
},
|
||
"jest-junit": {
|
||
"suiteName": "Unleash Unit Tests",
|
||
"outputDirectory": "./reports",
|
||
"outputName": "jest-junit.xml",
|
||
"uniqueOutputName": "false",
|
||
"classNameTemplate": "{classname}-{title}",
|
||
"titleTemplate": "{classname}-{title}",
|
||
"ancestorSeparator": " › ",
|
||
"usePathForSuiteName": "true"
|
||
},
|
||
"jest": {
|
||
"automock": false,
|
||
"maxWorkers": 4,
|
||
"testTimeout": 20000,
|
||
"globalSetup": "./scripts/jest-setup.ts",
|
||
"transform": {
|
||
"^.+\\.tsx?$": [
|
||
"@swc/jest"
|
||
]
|
||
},
|
||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||
"testPathIgnorePatterns": [
|
||
"/dist/",
|
||
"/node_modules/",
|
||
"/frontend/",
|
||
"/website/"
|
||
],
|
||
"moduleFileExtensions": [
|
||
"ts",
|
||
"tsx",
|
||
"js",
|
||
"jsx",
|
||
"json"
|
||
],
|
||
"coveragePathIgnorePatterns": [
|
||
"/node_modules/",
|
||
"/dist/",
|
||
"/src/migrations",
|
||
"/src/test"
|
||
]
|
||
},
|
||
"dependencies": {
|
||
"@slack/web-api": "^7.3.4",
|
||
"@wesleytodd/openapi": "^1.1.0",
|
||
"ajv": "^8.12.0",
|
||
"ajv-formats": "^2.1.1",
|
||
"async": "^3.2.4",
|
||
"bcryptjs": "^2.4.3",
|
||
"compression": "^1.7.4",
|
||
"connect-session-knex": "^5.0.0",
|
||
"cookie-parser": "^1.4.6",
|
||
"cookie-session": "^2.0.0-rc.1",
|
||
"cors": "^2.8.5",
|
||
"date-fns": "^2.25.0",
|
||
"db-migrate": "0.11.14",
|
||
"db-migrate-pg": "1.5.2",
|
||
"db-migrate-shared": "1.2.0",
|
||
"deep-object-diff": "^1.1.9",
|
||
"deepmerge": "^4.3.1",
|
||
"errorhandler": "^1.5.1",
|
||
"express": "^4.21.2",
|
||
"express-rate-limit": "^7.3.1",
|
||
"express-session": "^1.17.3",
|
||
"fast-json-patch": "^3.1.0",
|
||
"hash-sum": "^2.0.0",
|
||
"helmet": "^6.0.0",
|
||
"http-errors": "^2.0.0",
|
||
"hyperloglog-lite": "^1.0.2",
|
||
"ip-address": "^10.0.1",
|
||
"joi": "^17.13.3",
|
||
"js-sha256": "^0.11.0",
|
||
"js-yaml": "^4.1.0",
|
||
"json-diff": "^1.0.6",
|
||
"json-schema-to-ts": "2.12.0",
|
||
"json2csv": "^5.0.7",
|
||
"knex": "^3.1.0",
|
||
"lodash.get": "^4.4.2",
|
||
"lodash.groupby": "^4.6.0",
|
||
"lodash.sortby": "^4.7.0",
|
||
"log4js": "^6.0.0",
|
||
"make-fetch-happen": "^13.0.1",
|
||
"memoizee": "^0.4.17",
|
||
"mime": "^4.0.4",
|
||
"murmurhash3js": "^3.0.1",
|
||
"mustache": "^4.1.0",
|
||
"nodemailer": "^6.9.9",
|
||
"openapi-types": "^12.1.3",
|
||
"owasp-password-strength-test": "^1.3.0",
|
||
"parse-database-url": "^0.3.0",
|
||
"pg": "^8.12.0",
|
||
"pg-connection-string": "^2.5.0",
|
||
"pkginfo": "^0.4.1",
|
||
"prom-client": "^14.0.0",
|
||
"response-time": "^2.3.2",
|
||
"sanitize-filename": "^1.6.3",
|
||
"semver": "^7.6.3",
|
||
"serve-favicon": "^2.5.0",
|
||
"slug": "^9.0.0",
|
||
"stoppable": "^1.1.0",
|
||
"ts-toolbelt": "^9.6.0",
|
||
"type-is": "^1.6.18",
|
||
"unleash-client": "^6.4.0",
|
||
"uuid": "^9.0.0"
|
||
},
|
||
"devDependencies": {
|
||
"@apidevtools/swagger-parser": "10.1.1",
|
||
"@babel/core": "7.26.7",
|
||
"@biomejs/biome": "^1.9.4",
|
||
"@cyclonedx/yarn-plugin-cyclonedx": "^1.0.0-rc.7",
|
||
"@swc/core": "1.10.12",
|
||
"@swc/jest": "0.2.37",
|
||
"@types/bcryptjs": "2.4.6",
|
||
"@types/cors": "2.8.17",
|
||
"@types/express": "4.17.21",
|
||
"@types/express-session": "1.18.1",
|
||
"@types/faker": "5.5.9",
|
||
"@types/hash-sum": "^1.0.0",
|
||
"@types/jest": "29.5.14",
|
||
"@types/js-yaml": "4.0.9",
|
||
"@types/lodash.groupby": "4.6.9",
|
||
"@types/make-fetch-happen": "10.0.4",
|
||
"@types/memoizee": "0.4.11",
|
||
"@types/mime": "4.0.0",
|
||
"@types/mustache": "^4.2.5",
|
||
"@types/node": "20.17.16",
|
||
"@types/nodemailer": "6.4.17",
|
||
"@types/owasp-password-strength-test": "1.3.2",
|
||
"@types/pg": "8.11.11",
|
||
"@types/semver": "7.5.8",
|
||
"@types/slug": "^5.0.8",
|
||
"@types/stoppable": "1.1.3",
|
||
"@types/supertest": "6.0.2",
|
||
"@types/type-is": "1.6.7",
|
||
"@types/uuid": "9.0.8",
|
||
"concurrently": "^8.0.1",
|
||
"copyfiles": "2.4.1",
|
||
"coveralls": "3.1.1",
|
||
"del-cli": "5.1.0",
|
||
"faker": "5.5.3",
|
||
"fast-check": "3.23.2",
|
||
"fetch-mock": "^11.1.3",
|
||
"husky": "^9.0.11",
|
||
"jest": "29.7.0",
|
||
"jest-junit": "^16.0.0",
|
||
"lint-staged": "15.4.3",
|
||
"nock": "13.5.6",
|
||
"openapi-enforcer": "1.23.0",
|
||
"proxyquire": "2.1.3",
|
||
"source-map-support": "0.5.21",
|
||
"superagent": "9.0.2",
|
||
"supertest": "7.0.0",
|
||
"ts-node": "10.9.2",
|
||
"tsc-watch": "6.2.1",
|
||
"typescript": "5.4.5",
|
||
"wait-on": "^7.2.0"
|
||
},
|
||
"resolutions": {
|
||
"async": "^3.2.4",
|
||
"es5-ext": "0.10.64",
|
||
"node-forge": "^1.0.0",
|
||
"set-value": "^4.0.1",
|
||
"ansi-regex": "^5.0.1",
|
||
"ssh2": "^1.4.0",
|
||
"json-schema": "^0.4.0",
|
||
"ip": "^2.0.1",
|
||
"tar": "7.4.3",
|
||
"minimatch": "^5.0.0",
|
||
"semver": "^7.6.2",
|
||
"tough-cookie": "4.1.4",
|
||
"@wesleytodd/openapi/path-to-regexp": "6.3.0",
|
||
"router/path-to-regexp": "1.9.0",
|
||
"prompt": "link:./node_modules/.cache/null"
|
||
},
|
||
"lint-staged": {
|
||
"*.{js,ts}": [
|
||
"yarn biome check --write --no-errors-on-unmatched"
|
||
],
|
||
"*.{jsx,tsx}": [
|
||
"yarn biome check --write --no-errors-on-unmatched"
|
||
],
|
||
"*.json": [
|
||
"yarn biome format --write --no-errors-on-unmatched"
|
||
]
|
||
},
|
||
"packageManager": "yarn@4.6.0"
|
||
}
|