mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-12 00:48:21 -05:00
fix!: the test command should pass all args to the underlying script (#8619)
This commit is contained in:
6
.changeset/friendly-carrots-poke.md
Normal file
6
.changeset/friendly-carrots-poke.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": major
|
||||
"pnpm": major
|
||||
---
|
||||
|
||||
`pnpm test` should pass all the params after the `test` keyword to the underlying script. This is similar to how `pnpm run test` works [#8619](https://github.com/pnpm/pnpm/pull/8619).
|
||||
@@ -3,11 +3,5 @@ import * as dlx from './dlx'
|
||||
import * as exec from './exec'
|
||||
import * as restart from './restart'
|
||||
import * as run from './run'
|
||||
import * as _test from './test'
|
||||
|
||||
const test = {
|
||||
...run,
|
||||
..._test,
|
||||
}
|
||||
|
||||
export { create, dlx, exec, restart, run, test }
|
||||
export { create, dlx, exec, restart, run }
|
||||
|
||||
@@ -187,7 +187,7 @@ export async function handler (
|
||||
params: string[]
|
||||
): Promise<string | { exitCode: number } | undefined> {
|
||||
let dir: string
|
||||
const [scriptName, ...passedThruArgs] = params
|
||||
let [scriptName, ...passedThruArgs] = params
|
||||
if (opts.recursive) {
|
||||
if (scriptName || Object.keys(opts.selectedProjectsGraph).length > 1) {
|
||||
return runRecursive(params, opts) as Promise<undefined>
|
||||
@@ -203,6 +203,9 @@ export async function handler (
|
||||
: undefined
|
||||
return printProjectCommands(manifest, rootManifest ?? undefined)
|
||||
}
|
||||
if (opts.fallbackCommandUsed && (scriptName === 't' || scriptName === 'tst')) {
|
||||
scriptName = 'test'
|
||||
}
|
||||
|
||||
const specifiedScripts = getSpecifiedScripts(manifest.scripts ?? {}, scriptName)
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { FILTERING } from '@pnpm/common-cli-options-help'
|
||||
import renderHelp from 'render-help'
|
||||
import * as run from './run'
|
||||
|
||||
export const commandNames = ['test', 't', 'tst']
|
||||
|
||||
export function help (): string {
|
||||
return renderHelp({
|
||||
aliases: ['t', 'tst'],
|
||||
description: 'Runs a package\'s "test" script, if one was provided.',
|
||||
descriptionLists: [
|
||||
{
|
||||
title: 'Options',
|
||||
|
||||
list: [
|
||||
{
|
||||
description: '\
|
||||
Run the tests in every package found in subdirectories \
|
||||
or every workspace package, when executed inside a workspace. \
|
||||
For options that may be used with `-r`, see "pnpm help recursive"',
|
||||
name: '--recursive',
|
||||
shortAlias: '-r',
|
||||
},
|
||||
],
|
||||
},
|
||||
FILTERING,
|
||||
],
|
||||
url: docsUrl('test'),
|
||||
usages: ['pnpm test [-- <args>...]'],
|
||||
})
|
||||
}
|
||||
|
||||
export async function handler (
|
||||
opts: run.RunOpts,
|
||||
params: string[] = []
|
||||
): Promise<string | { exitCode: number } | undefined> {
|
||||
return run.handler(opts, ['test', ...params])
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import { filterPackagesFromDir } from '@pnpm/workspace.filter-packages-from-dir'
|
||||
import {
|
||||
restart,
|
||||
run,
|
||||
test as testCommand,
|
||||
} from '@pnpm/plugin-commands-script-runners'
|
||||
import { prepare, preparePackages } from '@pnpm/prepare'
|
||||
import { createTestIpcServer } from '@pnpm/test-ipc-server'
|
||||
@@ -137,14 +136,14 @@ test('test: pass the args to the command that is specified in the build script o
|
||||
fs.writeFileSync('args.json', '[]', 'utf8')
|
||||
fs.writeFileSync('recordArgs.js', RECORD_ARGS_FILE, 'utf8')
|
||||
|
||||
await testCommand.handler({
|
||||
await run.handler({
|
||||
bin: 'node_modules/.bin',
|
||||
dir: process.cwd(),
|
||||
extraBinPaths: [],
|
||||
extraEnv: {},
|
||||
pnpmHomeDir: '',
|
||||
rawConfig: {},
|
||||
}, ['arg', '--flag=true', '--help', '-h'])
|
||||
}, ['test', 'arg', '--flag=true', '--help', '-h'])
|
||||
|
||||
const { default: args } = await import(path.resolve('args.json'))
|
||||
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import path from 'path'
|
||||
import { filterPkgsBySelectorObjects } from '@pnpm/filter-workspace-packages'
|
||||
import { filterPackagesFromDir } from '@pnpm/workspace.filter-packages-from-dir'
|
||||
import { test as testCommand } from '@pnpm/plugin-commands-script-runners'
|
||||
import { run } from '@pnpm/plugin-commands-script-runners'
|
||||
import { preparePackages } from '@pnpm/prepare'
|
||||
import { createTestIpcServer } from '@pnpm/test-ipc-server'
|
||||
import execa from 'execa'
|
||||
@@ -62,14 +62,14 @@ test('pnpm recursive test', async () => {
|
||||
'--store-dir',
|
||||
path.resolve(DEFAULT_OPTS.storeDir),
|
||||
])
|
||||
await testCommand.handler({
|
||||
await run.handler({
|
||||
...DEFAULT_OPTS,
|
||||
allProjects,
|
||||
dir: process.cwd(),
|
||||
recursive: true,
|
||||
selectedProjectsGraph,
|
||||
workspaceDir: process.cwd(),
|
||||
})
|
||||
}, ['test'])
|
||||
|
||||
expect(server1.getLines()).toStrictEqual(['project-1', 'project-2'])
|
||||
expect(server2.getLines()).toStrictEqual(['project-1', 'project-3'])
|
||||
@@ -116,14 +116,14 @@ test('`pnpm recursive test` does not fail if none of the packages has a test com
|
||||
path.resolve(DEFAULT_OPTS.storeDir),
|
||||
])
|
||||
|
||||
await testCommand.handler({
|
||||
await run.handler({
|
||||
...DEFAULT_OPTS,
|
||||
allProjects,
|
||||
dir: process.cwd(),
|
||||
recursive: true,
|
||||
selectedProjectsGraph,
|
||||
workspaceDir: process.cwd(),
|
||||
})
|
||||
}, ['test'])
|
||||
})
|
||||
|
||||
test('pnpm recursive test with filtering', async () => {
|
||||
@@ -166,14 +166,14 @@ test('pnpm recursive test with filtering', async () => {
|
||||
'--store-dir',
|
||||
path.resolve(DEFAULT_OPTS.storeDir),
|
||||
])
|
||||
await testCommand.handler({
|
||||
await run.handler({
|
||||
...DEFAULT_OPTS,
|
||||
allProjects,
|
||||
dir: process.cwd(),
|
||||
recursive: true,
|
||||
selectedProjectsGraph,
|
||||
workspaceDir: process.cwd(),
|
||||
})
|
||||
}, ['test'])
|
||||
|
||||
expect(server.getLines()).toStrictEqual(['project-1'])
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
exec,
|
||||
restart,
|
||||
run,
|
||||
test,
|
||||
} from '@pnpm/plugin-commands-script-runners'
|
||||
import { server } from '@pnpm/plugin-commands-server'
|
||||
import { setup } from '@pnpm/plugin-commands-setup'
|
||||
@@ -150,7 +149,6 @@ const commands: CommandDefinition[] = [
|
||||
catFile,
|
||||
catIndex,
|
||||
findHash,
|
||||
test,
|
||||
unlink,
|
||||
update,
|
||||
why,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { docsUrl } from '@pnpm/cli-utils'
|
||||
import { install } from '@pnpm/plugin-commands-installation'
|
||||
import { test } from '@pnpm/plugin-commands-script-runners'
|
||||
import { run } from '@pnpm/plugin-commands-script-runners'
|
||||
import renderHelp from 'render-help'
|
||||
import { type PnpmOptions } from '../types'
|
||||
|
||||
@@ -21,5 +21,5 @@ export function help (): string {
|
||||
|
||||
export async function handler (opts: PnpmOptions, params: string[]): Promise<void> {
|
||||
await install.handler(opts)
|
||||
await test.handler(opts as any, params) // eslint-disable-line
|
||||
await run.handler(opts as any, ['test', ...params]) // eslint-disable-line
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ test.each([
|
||||
{ message: 'npm_command env available on special lifecycle hooks', script: 'prepare', command: 'install' },
|
||||
{ message: 'npm_command env available on special lifecycle hooks (alias)', script: 'prepare', command: 'i', expected: 'install' },
|
||||
{ message: 'npm_command env available on pre lifecycle hooks', script: 'prepack', command: 'pack' },
|
||||
{ message: 'npm_command env available on special commands', script: 'test', command: 'test' },
|
||||
{ message: 'npm_command env available on special commands', script: 'test', command: 'test', expected: 'run-script' },
|
||||
{ message: 'npm_command env available on scripts', script: 'dev', command: 'dev', expected: 'run-script' },
|
||||
])('$message', async ({ script, command, expected }) => {
|
||||
prepare({
|
||||
|
||||
@@ -52,7 +52,7 @@ test.each([
|
||||
writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
|
||||
await execPnpm(['install'])
|
||||
|
||||
await execPnpm(['recursive', filter, '...project-3', 'test'])
|
||||
await execPnpm([filter, '...project-3', 'test'])
|
||||
|
||||
expect(server.getLines().sort()).toEqual(expected)
|
||||
})
|
||||
|
||||
@@ -335,7 +335,7 @@ test('topological order of packages with self-dependencies in monorepo is correc
|
||||
|
||||
expect(server1.getLines()).toStrictEqual(['project-2', 'project-3', 'project-1'])
|
||||
|
||||
await execPnpm(['recursive', 'test'])
|
||||
await execPnpm(['-r', 'test'])
|
||||
|
||||
expect(server2.getLines()).toStrictEqual(['project-2', 'project-3', 'project-1'])
|
||||
})
|
||||
@@ -400,7 +400,7 @@ test('test-pattern is respected by the test script', async () => {
|
||||
|
||||
await execPnpm(['install'])
|
||||
|
||||
await execPnpm(['recursive', '--filter', '...[origin/main]', 'test'])
|
||||
await execPnpm(['--filter', '...[origin/main]', 'test'])
|
||||
|
||||
// Expecting only project-2 and project-4 to run since they were changed above.
|
||||
expect(server.getLines().sort()).toEqual(['project-2', 'project-4'])
|
||||
|
||||
Reference in New Issue
Block a user