diff --git a/.vscode/settings.json b/.vscode/settings.json index f30ff743c1..6b38da7014 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,8 +41,9 @@ "**/coverage": true, "**/dist": true }, - "jestrunner.enableYarnPnpSupport": true, - "jestrunner.jestCommand": "node scripts/jest.cjs", - "jestrunner.yarnPnpCommand": "../../scripts/yarn.cjs", "jestrunner.changeDirectoryToWorkspaceRoot": true, + "jestrunner.jestCommand": "node scripts/test.cjs", + "jestrunner.enableYarnPnpSupport": true, + // The command is prefixed with `.yarn/releases/`, so we need `../..` (see https://github.com/firsttris/vscode-jest-runner/blob/4dea33a0f692a8f1519dbb8b2567787ffe1843da/src/jestRunner.ts#L180) + "jestrunner.yarnPnpCommand": "../../scripts/debug.cjs" } diff --git a/scripts/debug.cjs b/scripts/debug.cjs new file mode 100644 index 0000000000..69fcbd28b0 --- /dev/null +++ b/scripts/debug.cjs @@ -0,0 +1,29 @@ +#!/usr/bin/env node +// +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors +// +// SPDX-License-Identifier: Apache-2.0 +// + +const assert = require('assert').strict +const { spawn } = require('child_process') +const { findYarnWorkspace } = require('./helper.cjs') + +const args = process.argv.slice(3) +const workspace = findYarnWorkspace(args[0]) +assert(workspace, 'yarn workspace not found') + +if (workspace.name === '@gardener-dashboard/frontend') { + const index = args.indexOf('--runInBand') + if (index !== -1) { + args.splice(index, 1) + } +} +args.push('--maxConcurrency=1', '--testTimeout=0') + +const cmd = spawn('yarn', ['workspace', workspace.name, 'run', 'test', ...args], { + stdio: 'inherit', + env: process.env, +}) +cmd.once('error', err => process.stderr.write(err.message + '\n')) +cmd.once('exit', code => process.exit(code)) diff --git a/scripts/helper.cjs b/scripts/helper.cjs index e142467612..10c1095e01 100644 --- a/scripts/helper.cjs +++ b/scripts/helper.cjs @@ -16,7 +16,7 @@ const packageJson = require('../package.json') const repodir = path.dirname(__dirname) function getWorkspaces () { - const today = new Date().toISOString().substring(0, 10) + const today = new Date().toISOString().substring(0, 10) const hash = crypto.createHash('md5').update(JSON.stringify(packageJson.workspaces)).digest('hex') const filename = path.join(os.tmpdir(), `gardener-dashboard-${today}`, `workspaces.${hash}.json`) @@ -25,14 +25,14 @@ function getWorkspaces () { } catch (err) { if (err.code !== 'ENOENT') { throw err - } + } } const workspaces = execSync('yarn workspaces list --json') .toString('utf8') .split('\n') .filter(val => val.startsWith('{') && val.endsWith('}') ) - .map(val => JSON.parse(val)) + .map(val => JSON.parse(val)) fs.mkdirSync(path.dirname(filename), { recursive: true }) fs.writeFileSync(filename, JSON.stringify(workspaces), 'utf8') @@ -47,31 +47,6 @@ function findYarnWorkspace (filename) { return workspaces.find(({ location }) => testfileLocation.startsWith(location)) } -function findJestConfig (workspace) { - const workspacedir = path.join(repodir, workspace.location) - const configfile = fs.readdirSync(workspacedir).find(name => { - if (name === 'jest.config.js' || name == 'jest.config.json') { - return true - } - if (name === 'package.json') { - const jest = require(path.join(workspacedir, 'package.json')) - return !!jest - } - return false - }) - return path.join(workspacedir, configfile) -} - -function findYarnCommand () { - const yarndir = path.join(repodir, '.yarn', 'releases') - const filename = fs.readdirSync(yarndir).find(filename => /^yarn-.+\.c?js$/.test(filename)) - if (filename) { - return path.join(yarndir, filename) - } -} - module.exports = { findYarnWorkspace, - findYarnCommand, - findJestConfig, } diff --git a/scripts/jest.cjs b/scripts/jest.cjs deleted file mode 100644 index dace841b89..0000000000 --- a/scripts/jest.cjs +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env node -// -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors -// -// SPDX-License-Identifier: Apache-2.0 -// - -const assert = require('assert').strict -const { spawn } = require('child_process') -const { findYarnWorkspace, findJestConfig } = require('./helper.cjs') - -const args = process.argv.slice(2) -const workspace = findYarnWorkspace(args[0]) -assert(workspace, 'yarn workspace not found') - -const jestConfig = findJestConfig(workspace) -assert(jestConfig, 'jest configuration not found') -process.argv.push('--config', jestConfig) - -const cmd = spawn('yarn', ['workspace', workspace.name, 'run', 'test', ...args], { - stdio: 'inherit' -}) -cmd.on('error', err => { - console.error(err.message) -}) -cmd.on('exit', code => process.exit(code)) diff --git a/scripts/test.cjs b/scripts/test.cjs new file mode 100644 index 0000000000..fcaf21d3df --- /dev/null +++ b/scripts/test.cjs @@ -0,0 +1,20 @@ +#!/usr/bin/env node +// +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors +// +// SPDX-License-Identifier: Apache-2.0 +// + +const assert = require('assert').strict +const { spawn } = require('child_process') +const { findYarnWorkspace } = require('./helper.cjs') + +const args = process.argv.slice(2) +const workspace = findYarnWorkspace(args[0]) +assert(workspace, 'yarn workspace not found') + +const cmd = spawn('yarn', ['workspace', workspace.name, 'run', 'test', ...args], { + stdio: 'inherit' +}) +cmd.once('error', err => process.stderr.write(err.message + '\n')) +cmd.once('exit', code => process.exit(code)) diff --git a/scripts/yarn.cjs b/scripts/yarn.cjs deleted file mode 100644 index d6b5e9c5a0..0000000000 --- a/scripts/yarn.cjs +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env node -// -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors -// -// SPDX-License-Identifier: Apache-2.0 -// - -const assert = require('assert').strict -const { findYarnWorkspace, findJestConfig, findYarnCommand } = require('./helper.cjs') - -const workspace = findYarnWorkspace(process.argv[3]) -assert(workspace, 'yarn workspace not found') - -const jestConfig = findJestConfig(workspace) -assert(jestConfig, 'jest configuration not found') -process.argv.push('--config', jestConfig) - -const yarnCommand = findYarnCommand() -assert(yarnCommand, 'yarn command not found') - -require(yarnCommand)