mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-07 23:48:05 -04:00
155 lines
3.3 KiB
TypeScript
155 lines
3.3 KiB
TypeScript
import { recursive } from '@pnpm/plugin-commands-recursive'
|
|
import { preparePackages } from '@pnpm/prepare'
|
|
import path = require('path')
|
|
import test = require('tape')
|
|
import { DEFAULT_OPTS } from './utils'
|
|
|
|
test('pnpm recursive test', async (t) => {
|
|
const projects = preparePackages(t, [
|
|
{
|
|
name: 'project-1',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'json-append': '1',
|
|
},
|
|
scripts: {
|
|
test: `node -e "process.stdout.write('project-1')" | json-append ../output1.json && node -e "process.stdout.write('project-1')" | json-append ../output2.json`,
|
|
},
|
|
},
|
|
{
|
|
name: 'project-2',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'json-append': '1',
|
|
'project-1': '1'
|
|
},
|
|
scripts: {
|
|
test: `node -e "process.stdout.write('project-2')" | json-append ../output1.json`,
|
|
},
|
|
},
|
|
{
|
|
name: 'project-3',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'json-append': '1',
|
|
'project-1': '1'
|
|
},
|
|
scripts: {
|
|
test: `node -e "process.stdout.write('project-3')" | json-append ../output2.json`,
|
|
},
|
|
},
|
|
{
|
|
name: 'project-0',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {},
|
|
},
|
|
])
|
|
|
|
await recursive.handler(['install'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
})
|
|
await recursive.handler(['test'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
})
|
|
|
|
const outputs1 = await import(path.resolve('output1.json')) as string[]
|
|
const outputs2 = await import(path.resolve('output2.json')) as string[]
|
|
|
|
t.deepEqual(outputs1, ['project-1', 'project-2'])
|
|
t.deepEqual(outputs2, ['project-1', 'project-3'])
|
|
t.end()
|
|
})
|
|
|
|
test('`pnpm recursive test` does not fail if none of the packaegs has a test command', async (t) => {
|
|
const projects = preparePackages(t, [
|
|
{
|
|
name: 'project-1',
|
|
version: '1.0.0',
|
|
},
|
|
{
|
|
name: 'project-2',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'project-1': '1'
|
|
},
|
|
},
|
|
{
|
|
name: 'project-3',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'project-1': '1'
|
|
},
|
|
},
|
|
{
|
|
name: 'project-0',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {},
|
|
},
|
|
])
|
|
|
|
await recursive.handler(['install'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
})
|
|
|
|
await recursive.handler(['test'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
})
|
|
|
|
t.pass('command did not fail')
|
|
t.end()
|
|
})
|
|
|
|
test('pnpm recursive test with filtering', async (t) => {
|
|
const projects = preparePackages(t, [
|
|
{
|
|
name: 'project-1',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'json-append': '1',
|
|
},
|
|
scripts: {
|
|
test: `node -e "process.stdout.write('project-1')" | json-append ../output.json`,
|
|
},
|
|
},
|
|
{
|
|
name: 'project-2',
|
|
version: '1.0.0',
|
|
|
|
dependencies: {
|
|
'json-append': '1',
|
|
'project-1': '1'
|
|
},
|
|
scripts: {
|
|
test: `node -e "process.stdout.write('project-2')" | json-append ../output.json`,
|
|
},
|
|
},
|
|
])
|
|
|
|
await recursive.handler(['install'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
})
|
|
await recursive.handler(['test'], {
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
filter: ['project-1'],
|
|
})
|
|
|
|
const outputs = await import(path.resolve('output.json')) as string[]
|
|
|
|
t.deepEqual(outputs, ['project-1'])
|
|
t.end()
|
|
})
|