From e532c39f5665e7ee9cb45df93aa231b861766c30 Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Wed, 8 May 2024 13:24:49 +1000 Subject: [PATCH] Ensure `sku-init` test does a thorough cleanup, run it separately to other tests (#962) --- .github/workflows/validate.yml | 2 +- .npmrc | 7 ----- {tests => fixtures/sku-init}/sku-init.test.js | 28 ++++++++++++++----- fixtures/sku-webpack-plugin/package.json | 1 + jest.config.js | 3 +- jest.config.sku-init.js | 11 ++++++++ package.json | 4 ++- pnpm-lock.yaml | 15 +++------- 8 files changed, 43 insertions(+), 28 deletions(-) rename {tests => fixtures/sku-init}/sku-init.test.js (56%) create mode 100644 jest.config.sku-init.js diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 8d9881574..9fc9b53ca 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -74,4 +74,4 @@ jobs: key: jest-${{ runner.os }}-${{ hashFiles('./pnpm-lock.yaml') }} - name: Test - run: pnpm run test --maxWorkers=2 + run: pnpm run test diff --git a/.npmrc b/.npmrc index 7e297afb5..1fe293379 100644 --- a/.npmrc +++ b/.npmrc @@ -2,14 +2,7 @@ public-hoist-pattern[]="*eslint*" public-hoist-pattern[]="*prettier*" -# `sku` itself needs these to be hoisted -public-hoist-pattern[]="babel-loader" -public-hoist-pattern[]="css-loader" - # This is only necessary in this repo because pnpm symlinks the sku dependency in fixtures to the sku package folder directly # This bypasses the .pnpm folder that resolveModules looks for # See https://github.com/seek-oss/sku/blob/275752bd3066e52885d461ef5bcd953aaac3bfff/config/webpack/resolveModules.js public-hoist-pattern[]="@babel/*" - -# Ensure that the same TypeScript version used by sku is used by the monorepo -public-hoist-pattern[]="typescript" diff --git a/tests/sku-init.test.js b/fixtures/sku-init/sku-init.test.js similarity index 56% rename from tests/sku-init.test.js rename to fixtures/sku-init/sku-init.test.js index 23b9bf97b..f5aff0eb3 100644 --- a/tests/sku-init.test.js +++ b/fixtures/sku-init/sku-init.test.js @@ -1,24 +1,38 @@ const path = require('node:path'); -const fs = require('node:fs'); -const { rimraf } = require('rimraf'); +const fs = require('node:fs/promises'); +const { promisify } = require('node:util'); +const exec = promisify(require('node:child_process').exec); const { runSkuScriptInDir } = require('@sku-private/test-utils'); -const fixtureDirectory = path.join(__dirname, '../fixtures/sku-init'); +const fixtureDirectory = __dirname; +const projectName = 'new-project'; +const projectDirectory = path.join(fixtureDirectory, projectName); describe('sku init', () => { + beforeAll(async () => { + await fs.rm(projectDirectory, { recursive: true, force: true }); + }); + + afterAll(async () => { + await fs.rm(projectDirectory, { recursive: true, force: true }); + + console.log( + "Running 'pnpm install' to clean up lockfile after sku-init test...", + ); + await exec('pnpm install'); + console.log('Cleanup complete'); + }); + it( 'should create a sku.config.ts', async () => { - const projectName = 'new-project'; - await rimraf(path.join(fixtureDirectory, projectName)); - const { child } = await runSkuScriptInDir('init', fixtureDirectory, [ projectName, ]); expect(child.exitCode).toBe(0); - const skuConfig = fs.readFileSync( + const skuConfig = await fs.readFile( path.join(fixtureDirectory, projectName, 'sku.config.ts'), 'utf-8', ); diff --git a/fixtures/sku-webpack-plugin/package.json b/fixtures/sku-webpack-plugin/package.json index 6a8d4c0ec..916b35a05 100644 --- a/fixtures/sku-webpack-plugin/package.json +++ b/fixtures/sku-webpack-plugin/package.json @@ -8,6 +8,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { + "babel-loader": "^9.1.2", "mini-css-extract-plugin": "^2.6.1", "html-webpack-plugin": "^5.3.2", "sku": "workspace:*" diff --git a/jest.config.js b/jest.config.js index 9c7e7f0e5..03cdd614d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,7 @@ module.exports = { transform: { '^.+\\.(t|j)sx?$': '@swc/jest', }, + maxWorkers: process.env.CI ? 2 : undefined, preset: 'jest-puppeteer', setupFilesAfterEnv: ['/test-utils/jestSetup.ts'], snapshotSerializers: [ @@ -13,7 +14,7 @@ module.exports = { testPathIgnorePatterns: [ '/node_modules/', '/packages/sku/scripts/test.js', - '/fixtures/.*/src', + '/fixtures/.*', ], watchPlugins: [ 'jest-watch-typeahead/filename', diff --git a/jest.config.sku-init.js b/jest.config.sku-init.js new file mode 100644 index 000000000..694f6e41b --- /dev/null +++ b/jest.config.sku-init.js @@ -0,0 +1,11 @@ +const { + testPathIgnorePatterns: _testPathIgnorePatterns, + ...baseJestConfig +} = require('./jest.config'); + +/** @type {import('jest').Config} */ +module.exports = { + ...baseJestConfig, + // Ensure that the only test that can be run with this config is sku-init.test.js + testRegex: 'sku-init\\.test\\.js$', +}; diff --git a/package.json b/package.json index c8ad840ec..9092ef405 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "lint:prettier": "prettier --cache --list-different '**/*.{js,ts,tsx,md,less,css}'", "lint:tsc": "tsc", "check": "pnpm install --frozen-lockfile && echo 'Ignore paths from lint-staged'", - "test": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true OPEN_TAB=false jest --verbose", + "test": "pnpm run test:rest && pnpm run test:sku-init", + "test:rest": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true OPEN_TAB=false jest --verbose", + "test:sku-init": "SKU_TELEMETRY=false SKU_DISABLE_CACHE=true OPEN_TAB=false jest --verbose --config=jest.config.sku-init.js", "setup-test-hosts": "node test-utils/setupTestHosts", "format": "prettier --cache --write '**/*.{js,ts,tsx,md,less,css}' && eslint --cache --fix .", "deploy-docs": "pnpm run --filter @sku-private/docs deploy", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 513a8ba81..f30f75f6c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: specifier: ^18.2.0 version: 18.3.1(react@18.3.1) devDependencies: + babel-loader: + specifier: ^9.1.2 + version: 9.1.3(@babel/core@7.24.5)(webpack@5.91.0) html-webpack-plugin: specifier: ^5.3.2 version: 5.6.0(webpack@5.91.0) @@ -6625,8 +6628,7 @@ packages: '@babel/core': 7.24.5 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.91.0(@swc/core@1.4.17)(esbuild@0.19.12) - dev: false + webpack: 5.91.0(@swc/core@1.4.17)(webpack-cli@5.1.4) /babel-plugin-add-react-displayname@0.0.5: resolution: {integrity: sha512-LY3+Y0XVDYcShHHorshrDbt4KFWL4bSeniCtl4SYZbask+Syngk1uMPCeN9+nSiZo6zX5s0RTq/J9Pnaaf/KHw==} @@ -7374,7 +7376,6 @@ packages: /common-path-prefix@3.0.0: resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==} - dev: false /commondir@1.0.1: resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} @@ -9422,7 +9423,6 @@ packages: dependencies: common-path-prefix: 3.0.0 pkg-dir: 7.0.0 - dev: false /find-file-up@0.1.3: resolution: {integrity: sha512-mBxmNbVyjg1LQIIpgO8hN+ybWBgDQK8qjht+EbrTCGmmPV/sc7RF1i9stPTD6bpvXZywBdrwRYxhSdJv867L6A==} @@ -9480,7 +9480,6 @@ packages: dependencies: locate-path: 7.2.0 path-exists: 5.0.0 - dev: false /find-yarn-workspace-root2@1.2.16: resolution: {integrity: sha512-hr6hb1w8ePMpPVUK39S4RlwJzi+xPLuVuG8XlwXU3KD5Yn3qgBWVfy3AzNlDhWvE1EORCE65/Qm26rFQt3VLVA==} @@ -11764,7 +11763,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: p-locate: 6.0.0 - dev: false /lodash.debounce@4.0.8: resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} @@ -12585,7 +12583,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: yocto-queue: 1.0.0 - dev: false /p-locate@3.0.0: resolution: {integrity: sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==} @@ -12611,7 +12608,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: p-limit: 4.0.0 - dev: false /p-map@2.1.0: resolution: {integrity: sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==} @@ -12753,7 +12749,6 @@ packages: /path-exists@5.0.0: resolution: {integrity: sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: false /path-is-absolute@1.0.1: resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} @@ -12872,7 +12867,6 @@ packages: engines: {node: '>=14.16'} dependencies: find-up: 6.3.0 - dev: false /pkg-types@1.1.0: resolution: {integrity: sha512-/RpmvKdxKf8uILTtoOhAgf30wYbP2Qw+L9p3Rvshx1JZVX+XQNZQFjlbmGHEGIm4CkVPlSn+NXmIM8+9oWQaSA==} @@ -16320,7 +16314,6 @@ packages: /yocto-queue@1.0.0: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} - dev: false github.com/zendesk/babel-plugin-react-displayname/7a837f2(@babel/core@7.24.5)(@babel/preset-react@7.24.1): resolution: {tarball: https://codeload.github.com/zendesk/babel-plugin-react-displayname/tar.gz/7a837f2}