|
| 1 | +/* eslint-disable no-console */ |
| 2 | + |
| 3 | +import { spawn } from 'child_process'; |
| 4 | +import { execa } from 'execa'; |
| 5 | +import path from 'path'; |
| 6 | + |
| 7 | +// resolved from the root of the project |
| 8 | +const inputDir = path.resolve('./test/fixtures/input'); |
| 9 | +const execOpts = { cwd: inputDir, stderr: 'inherit' }; |
| 10 | + |
| 11 | + |
| 12 | +console.log('installing deps'); |
| 13 | + |
| 14 | +await execa('rm', ['-rf', 'node_modules'], execOpts); |
| 15 | +await execa('yarn', ['install'], execOpts); |
| 16 | + |
| 17 | +console.log('starting serve'); |
| 18 | + |
| 19 | +// We use spawn for this one so we can kill it later without throwing an error |
| 20 | +const emberServe = spawn('yarn', ['start'], execOpts); |
| 21 | +emberServe.stderr.pipe(process.stderr); |
| 22 | +emberServe.stdout.pipe(process.stdout); |
| 23 | + |
| 24 | +await new Promise((resolve) => { |
| 25 | + emberServe.stdout.on('data', (data) => { |
| 26 | + if (data.toString().includes('Build successful')) { |
| 27 | + resolve(); |
| 28 | + } |
| 29 | + }); |
| 30 | +}); |
| 31 | + |
| 32 | +console.log('running codemod'); |
| 33 | + |
| 34 | +const codemod = execa( |
| 35 | + '../../../bin/cli.js', |
| 36 | + ['--telemetry', 'http://localhost:4200', 'app'], |
| 37 | + execOpts |
| 38 | +); |
| 39 | +codemod.stdout.pipe(process.stdout); |
| 40 | +await codemod; |
| 41 | + |
| 42 | +console.log('codemod complete, ending serve'); |
| 43 | + |
| 44 | +emberServe.kill('SIGTERM'); |
| 45 | + |
| 46 | +console.log('comparing results'); |
| 47 | + |
| 48 | +try { |
| 49 | + await execa('diff', ['-rq', './app', '../output/app'], execOpts); |
| 50 | +} catch (e) { |
| 51 | + console.error('codemod did not run successfully'); |
| 52 | + console.log(e); |
| 53 | + |
| 54 | + process.exit(1); |
| 55 | +} |
| 56 | + |
| 57 | +console.log('codemod ran successfully! 🎉'); |
0 commit comments