Skip to content

Commit 3ddff82

Browse files
committed
test: add tests
1 parent f10ffc4 commit 3ddff82

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

test/pnpmCatalog.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import type { CheckOptions } from '../src'
1+
import type { CheckOptions, PnpmWorkspaceMeta } from '../src'
2+
import fs from 'node:fs/promises'
23
import process from 'node:process'
34
import { expect, it } from 'vitest'
5+
import { parse, parseDocument } from 'yaml'
46
import { CheckPackages } from '../src'
7+
import { writePnpmWorkspace } from '../src/io/pnpmWorkspaces'
58

69
it('pnpm catalog', async () => {
710
const options: CheckOptions = {
@@ -100,3 +103,37 @@ it('pnpm catalog', async () => {
100103
]
101104
`)
102105
})
106+
107+
it('pnpm catalog updates should preserve yaml anchors and aliases with single string value', async () => {
108+
const workspaceYamlContents = `
109+
catalog:
110+
react: &foo ^18.2.0
111+
react-dom: *foo
112+
`
113+
const document = parseDocument(workspaceYamlContents)
114+
const pkg: PnpmWorkspaceMeta = {
115+
name: 'catalog:default',
116+
resolved: [
117+
// @ts-expect-error testing purpose
118+
{ name: 'react', targetVersion: '^18.3.1', source: 'pnpm:catalog', update: true, currentVersion: '^18.2.0', diff: 'minor' },
119+
// @ts-expect-error testing purpose
120+
{ name: 'react-dom', targetVersion: '^18.3.1', source: 'pnpm:catalog', update: true, currentVersion: '^18.2.0', diff: 'minor' },
121+
],
122+
raw: parse(workspaceYamlContents),
123+
document,
124+
filepath: '',
125+
type: 'pnpm-workspace.yaml',
126+
}
127+
128+
let output: string
129+
// @ts-expect-error testing purpose
130+
fs.writeFile = (_path, data, _ops) => output = data
131+
132+
await writePnpmWorkspace(pkg, {})
133+
// @ts-expect-error testing purpose
134+
expect(output).toMatchInlineSnapshot(`
135+
"catalog:
136+
react: &foo ^18.3.1
137+
react-dom: *foo
138+
"`)
139+
})

0 commit comments

Comments
 (0)