|
| 1 | +import { existsSync } from 'node:fs' |
| 2 | +import { rm } from 'node:fs/promises' |
| 3 | +import { join } from 'node:path' |
| 4 | +import { fileURLToPath } from 'node:url' |
| 5 | +import { x } from 'tinyexec' |
| 6 | +import { describe, expect, it } from 'vitest' |
| 7 | + |
| 8 | +const fixtureDir = fileURLToPath(new URL('../../../../../playground', import.meta.url)) |
| 9 | +const nuxi = fileURLToPath(new URL('../../../bin/nuxi.mjs', import.meta.url)) |
| 10 | + |
| 11 | +describe('nuxt add backwards compatibility', () => { |
| 12 | + it('should create middleware file using deprecated syntax', async () => { |
| 13 | + const file = join(fixtureDir, 'app/middleware/auth.ts') |
| 14 | + await rm(file, { force: true }) |
| 15 | + |
| 16 | + const res = await x(nuxi, ['add', 'middleware', 'auth'], { |
| 17 | + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, |
| 18 | + }) |
| 19 | + |
| 20 | + // Should show deprecation warning (check both stdout and stderr) |
| 21 | + const output = res.stdout + res.stderr |
| 22 | + expect(output).toContain('Deprecated') |
| 23 | + expect(output).toContain('add-template') |
| 24 | + |
| 25 | + // Should still create the file |
| 26 | + expect(existsSync(file)).toBe(true) |
| 27 | + |
| 28 | + await rm(file, { force: true }) |
| 29 | + }) |
| 30 | + |
| 31 | + it('should create page file using deprecated syntax', async () => { |
| 32 | + const file = join(fixtureDir, 'app/pages/test-page.vue') |
| 33 | + await rm(file, { force: true }) |
| 34 | + |
| 35 | + const res = await x(nuxi, ['add', 'page', 'test-page'], { |
| 36 | + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, |
| 37 | + }) |
| 38 | + |
| 39 | + const output = res.stdout + res.stderr |
| 40 | + expect(output).toContain('Deprecated') |
| 41 | + expect(existsSync(file)).toBe(true) |
| 42 | + |
| 43 | + await rm(file, { force: true }) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should create composable file using deprecated syntax', async () => { |
| 47 | + const file = join(fixtureDir, 'app/composables/useTestComposable.ts') |
| 48 | + await rm(file, { force: true }) |
| 49 | + |
| 50 | + const res = await x(nuxi, ['add', 'composable', 'useTestComposable'], { |
| 51 | + nodeOptions: { stdio: 'pipe', cwd: fixtureDir }, |
| 52 | + }) |
| 53 | + |
| 54 | + const output = res.stdout + res.stderr |
| 55 | + expect(output).toContain('Deprecated') |
| 56 | + expect(existsSync(file)).toBe(true) |
| 57 | + |
| 58 | + await rm(file, { force: true }) |
| 59 | + }) |
| 60 | +}) |
0 commit comments