|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { join } from 'path'; |
| 3 | +import { existsSync, writeFileSync } from 'fs'; |
| 4 | +import stripAnsi from 'strip-ansi'; |
| 5 | +import { newProjectWithFixtures } from './helpers.mjs'; |
| 6 | + |
| 7 | +const SCENARIOS = [ |
| 8 | + { |
| 9 | + name: 'defaults', |
| 10 | + flags: ['--minimal'], |
| 11 | + fixturePath: join(import.meta.dirname, 'fixture-gjs-only'), |
| 12 | + }, |
| 13 | + { |
| 14 | + name: 'typescript', |
| 15 | + flags: ['--typescript', '--minimal'], |
| 16 | + fixturePath: join(import.meta.dirname, 'fixture-gts-only'), |
| 17 | + }, |
| 18 | +]; |
| 19 | + |
| 20 | +describe('basic functionality', function () { |
| 21 | + for (let { name, flags, packageJson, fixturePath } of SCENARIOS) { |
| 22 | + describe(name, function () { |
| 23 | + let project = newProjectWithFixtures({ |
| 24 | + fixturePath, |
| 25 | + flags, |
| 26 | + packageJson, |
| 27 | + }); |
| 28 | + |
| 29 | + it('verify files', async function () { |
| 30 | + expect( |
| 31 | + !existsSync(join(project.dir(), 'app/index.html')), |
| 32 | + 'the app index.html has been removed', |
| 33 | + ); |
| 34 | + expect( |
| 35 | + existsSync(join(project.dir(), 'index.html')), |
| 36 | + 'the root index.html has been added', |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + it('successfully lints', async function () { |
| 41 | + let result = await project.execa('pnpm', ['lint']); |
| 42 | + |
| 43 | + console.log(result.stdout); |
| 44 | + }); |
| 45 | + |
| 46 | + it('successfully builds', async function () { |
| 47 | + let result = await project.execa('pnpm', ['build']); |
| 48 | + |
| 49 | + console.log(result.stdout); |
| 50 | + }); |
| 51 | + |
| 52 | + it('successfully runs tests', async function () { |
| 53 | + let result; |
| 54 | + |
| 55 | + try { |
| 56 | + result = await project.execa('pnpm', ['test']); |
| 57 | + } catch (err) { |
| 58 | + console.log(err.stdout, err.stderr); |
| 59 | + throw 'Failed to successfully run test'; |
| 60 | + } |
| 61 | + |
| 62 | + // make sure that each of the tests that we expect actually show up |
| 63 | + // alternatively we can change this to search for `pass 3` |
| 64 | + expect(result.stdout).to.contain( |
| 65 | + 'Acceptance | welcome page: visiting /index shows the welcome page', |
| 66 | + ); |
| 67 | + expect(result.stdout).to.contain( |
| 68 | + 'Acceptance | styles: visiting /styles', |
| 69 | + ); |
| 70 | + |
| 71 | + console.log(result.stdout); |
| 72 | + }); |
| 73 | + |
| 74 | + it('successfully runs tests in dev mode', async function () { |
| 75 | + await project.$`pnpm install --save-dev testem http-proxy`; |
| 76 | + let appURL; |
| 77 | + |
| 78 | + let server; |
| 79 | + |
| 80 | + try { |
| 81 | + server = project.execa('pnpm', ['start']); |
| 82 | + |
| 83 | + await new Promise((resolve) => { |
| 84 | + server.stdout.on('data', (line) => { |
| 85 | + let result = /Local:\s+(https?:\/\/.*)\//g.exec( |
| 86 | + stripAnsi(line.toString()), |
| 87 | + ); |
| 88 | + |
| 89 | + if (result) { |
| 90 | + appURL = result[1]; |
| 91 | + resolve(); |
| 92 | + } |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + writeFileSync( |
| 97 | + join(project.dir(), 'testem-dev.js'), |
| 98 | + `module.exports = { |
| 99 | + test_page: 'tests/index.html?hidepassed', |
| 100 | + disable_watching: true, |
| 101 | + launch_in_ci: ['Chrome'], |
| 102 | + launch_in_dev: ['Chrome'], |
| 103 | + browser_start_timeout: 120, |
| 104 | + browser_args: { |
| 105 | + Chrome: { |
| 106 | + ci: [ |
| 107 | + // --no-sandbox is needed when running Chrome inside a container |
| 108 | + process.env.CI ? '--no-sandbox' : null, |
| 109 | + '--headless', |
| 110 | + '--disable-dev-shm-usage', |
| 111 | + '--disable-software-rasterizer', |
| 112 | + '--mute-audio', |
| 113 | + '--remote-debugging-port=0', |
| 114 | + '--window-size=1440,900', |
| 115 | + ].filter(Boolean), |
| 116 | + }, |
| 117 | + }, |
| 118 | + middleware: [ |
| 119 | + require(__dirname + '/testem-proxy.js')('${appURL}') |
| 120 | + ], |
| 121 | +}; |
| 122 | +`, |
| 123 | + ); |
| 124 | + |
| 125 | + let testResult = await project.execa('pnpm', [ |
| 126 | + 'testem', |
| 127 | + '--file', |
| 128 | + 'testem-dev.js', |
| 129 | + 'ci', |
| 130 | + ]); |
| 131 | + expect(testResult.exitCode).to.eq(0, testResult.output); |
| 132 | + } finally { |
| 133 | + server?.kill('SIGINT'); |
| 134 | + } |
| 135 | + }); |
| 136 | + |
| 137 | + it('successfully optimizes deps', function () { |
| 138 | + return project.execa('pnpm', ['vite', 'optimize', '--force']); |
| 139 | + }); |
| 140 | + |
| 141 | + it('can run generators', function () { |
| 142 | + return project.execa('pnpm', ['ember', 'g', 'route', 'fancy']); |
| 143 | + }); |
| 144 | + }); |
| 145 | + } |
| 146 | +}); |
0 commit comments