From 7e38d6bae1201c3f06b882601372958223974a6c Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Thu, 23 May 2024 14:14:09 +0200 Subject: [PATCH] Node20 (#7095) Upgrades workflows, nvmrc and package.json to use Node 20. --- .github/workflows/build.yaml | 9 +-- .github/workflows/build_coverage.yaml | 4 +- .github/workflows/build_doc_prs.yaml | 2 +- .github/workflows/build_frontend_prs.yml | 2 +- .github/workflows/build_prs_jest_report.yaml | 8 +-- .github/workflows/docker_publish.yaml | 2 +- .../workflows/gradual-strict-null-checks.yml | 4 +- .github/workflows/notify_enterprise.yaml | 2 +- .github/workflows/publish-new-version.yaml | 2 +- .github/workflows/release.yaml | 4 +- .github/workflows/update_contributors.yaml | 4 +- .github/workflows/validate-migrations.yaml | 4 +- .nvmrc | 2 +- Dockerfile | 2 +- docker/package.json | 2 +- package.json | 2 +- .../__snapshots__/create-config.test.ts.snap | 1 + .../feature-lifecycle.e2e.test.ts | 2 +- .../frontend-api.concurrency.e2e.test.ts | 25 +++++---- src/test/e2e/helpers/test-helper.ts | 56 ++++++++++++++++++- yarn.lock | 40 +++---------- 21 files changed, 105 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 69e88d3474..c2a1cdc95c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,9 +17,6 @@ jobs: runs-on: ubuntu-latest name: build - strategy: - matrix: - node-version: [18.x] services: # Label used to access the service container postgres: @@ -38,10 +35,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js 20 uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node-version }} + node-version: 20.x cache: 'yarn' - run: yarn install --frozen-lockfile --ignore-scripts - run: yarn lint @@ -56,4 +53,4 @@ jobs: if: (success() || failure()) && github.ref == 'refs/heads/main' with: name: test-results - path: ./reports/jest-junit.xml \ No newline at end of file + path: ./reports/jest-junit.xml diff --git a/.github/workflows/build_coverage.yaml b/.github/workflows/build_coverage.yaml index 45cca0b410..22b7bb8ef7 100644 --- a/.github/workflows/build_coverage.yaml +++ b/.github/workflows/build_coverage.yaml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [20.x] services: # Label used to access the service container postgres: @@ -37,7 +37,7 @@ jobs: - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - run: yarn - run: yarn build:frontend:if-needed diff --git a/.github/workflows/build_doc_prs.yaml b/.github/workflows/build_doc_prs.yaml index 59b07dfabb..9166157433 100644 --- a/.github/workflows/build_doc_prs.yaml +++ b/.github/workflows/build_doc_prs.yaml @@ -7,7 +7,7 @@ on: jobs: validate: - name: build (18.x) # temporary solution to trick branch protection rules + name: build # temporary solution to trick branch protection rules runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/build_frontend_prs.yml b/.github/workflows/build_frontend_prs.yml index 7f7b2dbe18..cce3085b0b 100644 --- a/.github/workflows/build_frontend_prs.yml +++ b/.github/workflows/build_frontend_prs.yml @@ -13,7 +13,7 @@ jobs: working-directory: frontend strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} diff --git a/.github/workflows/build_prs_jest_report.yaml b/.github/workflows/build_prs_jest_report.yaml index e2378b2b0e..2841ea4ba5 100644 --- a/.github/workflows/build_prs_jest_report.yaml +++ b/.github/workflows/build_prs_jest_report.yaml @@ -12,7 +12,7 @@ on: jobs: build: runs-on: ubuntu-latest - name: build (18.x) # temporary solution to trick branch protection rules + name: build # temporary solution to trick branch protection rules services: # Label used to access the service container @@ -32,12 +32,12 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Use Node.js 18.x + - name: Use Node.js 20.x uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - - name: Tests on 18.x + - name: Tests on 20.x id: coverage uses: ArtiomTr/jest-coverage-report-action@v2 with: diff --git a/.github/workflows/docker_publish.yaml b/.github/workflows/docker_publish.yaml index 9fba8ef229..281598af8f 100644 --- a/.github/workflows/docker_publish.yaml +++ b/.github/workflows/docker_publish.yaml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: [18.18.2-alpine] + version: [20.13.1-alpine] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/gradual-strict-null-checks.yml b/.github/workflows/gradual-strict-null-checks.yml index fea1e4177a..59d171f4d8 100644 --- a/.github/workflows/gradual-strict-null-checks.yml +++ b/.github/workflows/gradual-strict-null-checks.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - name: Checkout current branch @@ -30,7 +30,7 @@ jobs: - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' cache-dependency-path: | current/yarn.lock diff --git a/.github/workflows/notify_enterprise.yaml b/.github/workflows/notify_enterprise.yaml index 3c388f7064..a7570c96be 100644 --- a/.github/workflows/notify_enterprise.yaml +++ b/.github/workflows/notify_enterprise.yaml @@ -20,7 +20,7 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/publish-new-version.yaml b/.github/workflows/publish-new-version.yaml index 8eb63f82a7..d608f581db 100644 --- a/.github/workflows/publish-new-version.yaml +++ b/.github/workflows/publish-new-version.yaml @@ -30,7 +30,7 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 70dea9efa0..dce9c7558b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,14 +10,14 @@ jobs: strategy: matrix: - node-version: [18.x] + node-version: [20.x] steps: - uses: actions/checkout@v4 - name: Setup to npm uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x registry-url: 'https://registry.npmjs.org' cache: 'yarn' - name: Build diff --git a/.github/workflows/update_contributors.yaml b/.github/workflows/update_contributors.yaml index 7af14fb429..8c4cefd3f5 100644 --- a/.github/workflows/update_contributors.yaml +++ b/.github/workflows/update_contributors.yaml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 18.x + - name: Use Node.js 20.x uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x - uses: actions/checkout@master with: repository: sighphyre/svg-contributors diff --git a/.github/workflows/validate-migrations.yaml b/.github/workflows/validate-migrations.yaml index a37654ea89..73761a82ac 100644 --- a/.github/workflows/validate-migrations.yaml +++ b/.github/workflows/validate-migrations.yaml @@ -15,10 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 18.x + - name: Use Node.js 20.x uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x cache: 'yarn' - name: Start database working-directory: test-migrations diff --git a/.nvmrc b/.nvmrc index 3c032078a4..209e3ef4b6 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -18 +20 diff --git a/Dockerfile b/Dockerfile index a1c8dd7aa9..ad65197cb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG NODE_VERSION=18.20.2-alpine +ARG NODE_VERSION=20.13.1-alpine FROM node:$NODE_VERSION as builder diff --git a/docker/package.json b/docker/package.json index 0b23a9c290..ec598165bc 100644 --- a/docker/package.json +++ b/docker/package.json @@ -7,7 +7,7 @@ "test:ci": "echo 'no tests for unleash-docker'" }, "engines": { - "node": ">=18" + "node": ">=20" }, "author": "", "license": "ISC", diff --git a/package.json b/package.json index 5283993cfc..a82b4a6f2d 100644 --- a/package.json +++ b/package.json @@ -206,7 +206,7 @@ "proxyquire": "2.1.3", "source-map-support": "0.5.21", "superagent": "9.0.2", - "supertest": "6.3.4", + "supertest": "7.0.0", "ts-node": "10.9.2", "tsc-watch": "6.2.0", "typescript": "5.4.2", diff --git a/src/lib/__snapshots__/create-config.test.ts.snap b/src/lib/__snapshots__/create-config.test.ts.snap index 3827498a33..96494cbcd6 100644 --- a/src/lib/__snapshots__/create-config.test.ts.snap +++ b/src/lib/__snapshots__/create-config.test.ts.snap @@ -69,6 +69,7 @@ exports[`should create default config 1`] = ` "_events": {}, "_eventsCount": 0, "_maxListeners": undefined, + Symbol(shapeMode): false, Symbol(kCapture): false, }, "feedbackUriPath": undefined, diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts b/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts index 56d05cb8e7..c4363041dd 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle.e2e.test.ts @@ -125,7 +125,7 @@ test('should return lifecycle stages', async () => { bucket: { toggles: { my_feature_a: 'irrelevant', - non_existent_feature: 'irrelevent', + non_existent_feature: 'irrelevant', }, }, environment: 'default', diff --git a/src/lib/features/frontend-api/frontend-api.concurrency.e2e.test.ts b/src/lib/features/frontend-api/frontend-api.concurrency.e2e.test.ts index ee108885cd..6e010ee1ee 100644 --- a/src/lib/features/frontend-api/frontend-api.concurrency.e2e.test.ts +++ b/src/lib/features/frontend-api/frontend-api.concurrency.e2e.test.ts @@ -1,13 +1,13 @@ import { - type IUnleashTest, - setupAppWithAuth, + type IUnleashNoSupertest, + setupAppWithoutSupertest, } from '../../../test/e2e/helpers/test-helper'; import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; import getLogger from '../../../test/fixtures/no-logger'; import { randomId } from '../../util'; import { ApiTokenType } from '../../types/models/api-token'; -let app: IUnleashTest; +let app: IUnleashNoSupertest; let db: ITestDb; let appErrorLogs: string[] = []; @@ -21,7 +21,7 @@ beforeAll(async () => { baseLogger.error(msg, ...args); }, }; - app = await setupAppWithAuth(db.stores, { + app = await setupAppWithoutSupertest(db.stores, { frontendApiOrigins: ['https://example.com'], getLogger: () => appLogger, }); @@ -53,14 +53,19 @@ test('multiple parallel calls to api/frontend should not create multiple instanc environment: 'default', tokenName: `test-token-${randomId()}`, }); - + const address = app.server.address(); + expect(address).not.toBeNull(); + expect(address).toHaveProperty('port'); + // @ts-ignore - We've just checked that we have this property + const serverUrl = `http://localhost:${address.port}/api/frontend`; await Promise.all( Array.from(Array(10).keys()).map(() => - app.request - .get('/api/frontend') - .set('Authorization', frontendTokenDefault.secret) - .expect('Content-Type', /json/) - .expect(200), + fetch(serverUrl, { + method: 'GET', + headers: { + Authorization: frontendTokenDefault.secret, + }, + }).then((res) => expect(res.status).toBe(200)), ), ); expect(appErrorLogs).toHaveLength(0); diff --git a/src/test/e2e/helpers/test-helper.ts b/src/test/e2e/helpers/test-helper.ts index 638acbbd4f..a06f4a5b5c 100644 --- a/src/test/e2e/helpers/test-helper.ts +++ b/src/test/e2e/helpers/test-helper.ts @@ -22,7 +22,7 @@ import type { import type { Knex } from 'knex'; import type TestAgent from 'supertest/lib/agent'; import type Test from 'supertest/lib/test'; - +import type { Server } from 'node:http'; process.env.NODE_ENV = 'test'; export interface IUnleashTest extends IUnleashHttpAPI { @@ -32,6 +32,13 @@ export interface IUnleashTest extends IUnleashHttpAPI { config: IUnleashConfig; } +export interface IUnleashNoSupertest { + server: Server; + services: IUnleashServices; + config: IUnleashConfig; + destroy: () => Promise; +} + /** * This is a collection of API helpers. The response code is optional, and should default to the success code for the request. * @@ -348,6 +355,53 @@ export async function setupApp(stores: IUnleashStores): Promise { return createApp(stores); } +export async function setupAppWithoutSupertest( + stores, + customOptions?: any, + db?: Db, +): Promise { + const config = createTestConfig({ + authentication: { + type: IAuthType.DEMO, + }, + server: { + unleashUrl: 'http://localhost:4242', + }, + disableScheduler: true, + ...{ + ...customOptions, + experimental: { + ...(customOptions?.experimental ?? {}), + flags: { + strictSchemaValidation: true, + ...(customOptions?.experimental?.flags ?? {}), + }, + }, + }, + }); + const services = createServices(stores, config, db); + const unleashSession = sessionDb(config, undefined); + const app = await getApp(config, stores, services, unleashSession, db); + const server = app.listen(0); + const destroy = async () => { + // iterate on the keys of services and if the services at that key has a function called destroy then call it + await Promise.all( + Object.keys(services).map(async (key) => { + if (services[key].destroy) { + await services[key].destroy(); + } + }), + ); + await server.close(); + }; + return { + server, + destroy, + services, + config, + }; +} + export async function setupAppWithCustomConfig( stores: IUnleashStores, // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types diff --git a/yarn.lock b/yarn.lock index fa85b8c892..30a11eb1c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3461,16 +3461,6 @@ form-data@~2.3.2: combined-stream "^1.0.6" mime-types "^2.1.12" -formidable@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/formidable/-/formidable-2.1.2.tgz#fa973a2bec150e4ce7cac15589d7a25fc30ebd89" - integrity sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g== - dependencies: - dezalgo "^1.0.4" - hexoid "^1.0.0" - once "^1.4.0" - qs "^6.11.0" - formidable@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/formidable/-/formidable-3.5.1.tgz#9360a23a656f261207868b1484624c4c8d06ee1a" @@ -6399,7 +6389,7 @@ sanitize-filename@^1.6.3: dependencies: truncate-utf8-bytes "^1.0.0" -semver@^5.3.0, semver@^6.0.0, semver@^6.3.0, semver@^6.3.1, semver@^7.3.4, semver@^7.3.5, semver@^7.3.8, semver@^7.5.3, semver@^7.5.4: +semver@^5.3.0, semver@^6.0.0, semver@^6.3.0, semver@^6.3.1, semver@^7.3.4, semver@^7.3.5, semver@^7.5.3, semver@^7.5.4: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== @@ -6911,7 +6901,7 @@ strip-json-comments@~2.0.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" integrity sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ== -superagent@9.0.2: +superagent@9.0.2, superagent@^9.0.1: version "9.0.2" resolved "https://registry.yarnpkg.com/superagent/-/superagent-9.0.2.tgz#a18799473fc57557289d6b63960610e358bdebc1" integrity sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w== @@ -6926,29 +6916,13 @@ superagent@9.0.2: mime "2.6.0" qs "^6.11.0" -superagent@^8.1.2: - version "8.1.2" - resolved "https://registry.yarnpkg.com/superagent/-/superagent-8.1.2.tgz#03cb7da3ec8b32472c9d20f6c2a57c7f3765f30b" - integrity sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA== - dependencies: - component-emitter "^1.3.0" - cookiejar "^2.1.4" - debug "^4.3.4" - fast-safe-stringify "^2.1.1" - form-data "^4.0.0" - formidable "^2.1.2" - methods "^1.1.2" - mime "2.6.0" - qs "^6.11.0" - semver "^7.3.8" - -supertest@6.3.4: - version "6.3.4" - resolved "https://registry.yarnpkg.com/supertest/-/supertest-6.3.4.tgz#2145c250570c2ea5d337db3552dbfb78a2286218" - integrity sha512-erY3HFDG0dPnhw4U+udPfrzXa4xhSG+n4rxfRuZWCUvjFWwKl+OxWf/7zk50s84/fAAs7vf5QAb9uRa0cCykxw== +supertest@7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/supertest/-/supertest-7.0.0.tgz#cac53b3d6872a0b317980b2b0cfa820f09cd7634" + integrity sha512-qlsr7fIC0lSddmA3tzojvzubYxvlGtzumcdHgPwbFWMISQwL22MhM2Y3LNt+6w9Yyx7559VW5ab70dgphm8qQA== dependencies: methods "^1.1.2" - superagent "^8.1.2" + superagent "^9.0.1" supports-color@^5.3.0: version "5.5.0"