|
| 1 | +import { rm } from 'node:fs/promises'; |
| 2 | +import { join, relative } from 'node:path'; |
| 3 | +import { afterEach, expect } from 'vitest'; |
| 4 | +import { removeColorCodes } from '@code-pushup/test-utils'; |
| 5 | +import { executeProcess } from '@code-pushup/utils'; |
| 6 | +import { createNpmWorkspace } from '../mocks/create-npm-workshpace'; |
| 7 | + |
| 8 | +describe('create-cli-node', () => { |
| 9 | + const baseDir = join('tmp', 'create-cli-e2e'); |
| 10 | + const bin = 'dist/packages/create-cli'; |
| 11 | + const binPath = (cwd?: string) => |
| 12 | + cwd ? relative(join(process.cwd(), cwd), join(process.cwd(), bin)) : bin; |
| 13 | + |
| 14 | + afterEach(async () => { |
| 15 | + await rm(baseDir, { recursive: true, force: true }); |
| 16 | + }); |
| 17 | + |
| 18 | + // eslint-disable-next-line vitest/no-disabled-tests |
| 19 | + it.skip('should execute index.js correctly over node', async () => { |
| 20 | + const cwd = join(baseDir, 'node-index-js'); |
| 21 | + await createNpmWorkspace(cwd); |
| 22 | + const { code, stdout } = await executeProcess({ |
| 23 | + command: 'node', |
| 24 | + args: [join(binPath(cwd), 'index.js')], |
| 25 | + cwd, |
| 26 | + }); |
| 27 | + |
| 28 | + expect(code).toBe(0); |
| 29 | + const cleanedStdout = removeColorCodes(stdout); |
| 30 | + expect(cleanedStdout).toContain( |
| 31 | + '<↗> Generating @code-pushup/nx-plugin:configuration', |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + // eslint-disable-next-line vitest/no-disabled-tests |
| 36 | + it.skip('should execute package correctly over npm exec', async () => { |
| 37 | + const cwd = join(baseDir, 'npm-exec'); |
| 38 | + await createNpmWorkspace(cwd); |
| 39 | + const { code, stdout } = await executeProcess({ |
| 40 | + command: 'npm', |
| 41 | + args: ['exec', '@code-pushup/create-cli'], |
| 42 | + cwd, |
| 43 | + observer: { onStdout: console.info }, |
| 44 | + }); |
| 45 | + |
| 46 | + expect(code).toBe(0); |
| 47 | + const cleanedStdout = removeColorCodes(stdout); |
| 48 | + expect(cleanedStdout).toContain( |
| 49 | + '<↗> Generating @code-pushup/nx-plugin:configuration', |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should execute package correctly over npm init', async () => { |
| 54 | + const cwd = join(baseDir, 'npm-init'); |
| 55 | + await createNpmWorkspace(cwd); |
| 56 | + const { code, stdout } = await executeProcess({ |
| 57 | + command: 'npm', |
| 58 | + args: ['init', '@code-pushup/cli'], |
| 59 | + cwd, |
| 60 | + observer: { onStdout: console.info }, |
| 61 | + }); |
| 62 | + |
| 63 | + expect(code).toBe(0); |
| 64 | + const cleanedStdout = removeColorCodes(stdout); |
| 65 | + expect(cleanedStdout).toContain( |
| 66 | + '<↗> Generating @code-pushup/nx-plugin:configuration', |
| 67 | + ); |
| 68 | + }); |
| 69 | +}); |
0 commit comments