|
1 | | -import { mkdtemp, rm, writeFile } from 'node:fs/promises' |
| 1 | +import { existsSync } from 'node:fs' |
| 2 | +import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' |
2 | 3 | import { tmpdir } from 'node:os' |
3 | 4 | import { join } from 'node:path' |
4 | 5 | import { afterEach, beforeEach, describe, expect, it } from 'vitest' |
5 | 6 |
|
6 | | -import { detectTemplatePackageManager, getNextSteps } from '../../../src/commands/init' |
| 7 | +import { detectTemplatePackageManager, getNextSteps, useYarnNodeModulesLinker } from '../../../src/commands/init' |
| 8 | + |
| 9 | +describe('useYarnNodeModulesLinker', () => { |
| 10 | + let dir: string |
| 11 | + |
| 12 | + beforeEach(async () => { |
| 13 | + dir = await mkdtemp(join(tmpdir(), 'nuxt-init-yarn-')) |
| 14 | + }) |
| 15 | + |
| 16 | + afterEach(async () => { |
| 17 | + await rm(dir, { recursive: true, force: true }) |
| 18 | + }) |
| 19 | + |
| 20 | + it('should opt a fresh project out of plug\'n\'play', async () => { |
| 21 | + expect(await useYarnNodeModulesLinker(dir)).toBe(true) |
| 22 | + expect(await readFile(join(dir, '.yarnrc.yml'), 'utf8')).toContain('nodeLinker: node-modules') |
| 23 | + }) |
| 24 | + |
| 25 | + it('should not overwrite yarn configuration from a template', async () => { |
| 26 | + await writeFile(join(dir, '.yarnrc.yml'), 'nodeLinker: pnp\n') |
| 27 | + expect(await useYarnNodeModulesLinker(dir)).toBe(false) |
| 28 | + expect(await readFile(join(dir, '.yarnrc.yml'), 'utf8')).toBe('nodeLinker: pnp\n') |
| 29 | + }) |
| 30 | + |
| 31 | + it('should not add yarn 2+ configuration alongside a yarn 1 config', async () => { |
| 32 | + await writeFile(join(dir, '.yarnrc'), 'registry "https://example.com"\n') |
| 33 | + expect(await useYarnNodeModulesLinker(dir)).toBe(false) |
| 34 | + expect(existsSync(join(dir, '.yarnrc.yml'))).toBe(false) |
| 35 | + }) |
| 36 | +}) |
7 | 37 |
|
8 | 38 | describe('getNextSteps', () => { |
9 | 39 | const base = { shell: false, recoveryCommands: [] as string[], packageManager: 'npm' as const } |
|
0 commit comments