Files
pnpm/cli/default-reporter/test/reportingContext.ts
Brandon Cheng b217edbfd8 test: fix silently failing tests in default-reporter package (#9253)
* test: move expect blocks (without other changes) to end of test

This is required for the refactor in the next commit. The log statements
have to run before consuming the output stream, otherwise the output
stream will be empty.

* test: fix swallowed Jest expect errors in `default-reporter` package

* test: fix expected to match actual values in default-reporter tests

* refactor: remove redundant `.pipe(take(1))`

With the refactor to use `firstValueFrom`, the `take(1)` is now
redundant in many places.

```ts
firstValueFrom(output$.pipe(take(1)))
```

```ts
firstValueFrom(output$)
```
2025-03-10 00:47:58 +01:00

86 lines
2.1 KiB
TypeScript

import { setTimeout } from 'node:timers/promises'
import { contextLogger, packageImportMethodLogger } from '@pnpm/core-loggers'
import { toOutput$ } from '@pnpm/default-reporter'
import {
createStreamParser,
} from '@pnpm/logger'
import { firstValueFrom } from 'rxjs'
const NO_OUTPUT = Symbol('test should not log anything')
test('print context and import method info', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
},
streamParser: createStreamParser(),
})
contextLogger.debug({
currentLockfileExists: false,
storeDir: '~/.pnpm-store/v3',
virtualStoreDir: 'node_modules/.pnpm',
})
packageImportMethodLogger.debug({
method: 'hardlink',
})
expect.assertions(1)
const output = await firstValueFrom(output$)
expect(output).toBe(`\
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: ~/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm`)
})
test('do not print info if not fresh install', async () => {
const output$ = toOutput$({
context: {
argv: ['install'],
},
streamParser: createStreamParser(),
})
contextLogger.debug({
currentLockfileExists: true,
storeDir: '~/.pnpm-store/v3',
virtualStoreDir: 'node_modules/.pnpm',
})
packageImportMethodLogger.debug({
method: 'hardlink',
})
const output = await Promise.race([
firstValueFrom(output$),
setTimeout(10).then(() => NO_OUTPUT),
])
expect(output).toEqual(NO_OUTPUT)
})
test('do not print info if dlx is the executed command', async () => {
const output$ = toOutput$({
context: {
argv: ['dlx'],
},
streamParser: createStreamParser(),
})
contextLogger.debug({
currentLockfileExists: false,
storeDir: '~/.pnpm-store/v3',
virtualStoreDir: 'node_modules/.pnpm',
})
packageImportMethodLogger.debug({
method: 'hardlink',
})
const output = await Promise.race([
firstValueFrom(output$),
setTimeout(10).then(() => NO_OUTPUT),
])
expect(output).toEqual(NO_OUTPUT)
})