-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from embroider-build/extract-helpers
Extract project creation util so that multiple test files can share the "ember new + fixture" stuff
- Loading branch information
Showing
2 changed files
with
89 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,77 @@ | ||
import assert from 'node:assert'; | ||
import { join } from 'node:path'; | ||
|
||
import { beforeAll, afterAll } from 'vitest'; | ||
import { sync as resolveBinSync } from 'resolve-bin'; | ||
import { execa } from 'execa'; | ||
import tmp from 'tmp-promise'; | ||
|
||
import copyWithTemplate from '../lib/copy-with-template'; | ||
|
||
function findEmber() { | ||
return resolveBinSync('ember-cli', { executable: 'ember' }); | ||
} | ||
|
||
export const emberCli = findEmber(); | ||
|
||
const blueprintPath = join(__dirname, '..'); | ||
const appName = 'fancy-app-in-test'; | ||
|
||
export function newProjectWithFixtures({ | ||
flags = [], | ||
fixturePath, | ||
name = appName, | ||
} = {}) { | ||
let tmpDir; | ||
|
||
assert(fixturePath, `a fixturePath is required`); | ||
|
||
beforeAll(async () => { | ||
tmpDir = await tmp.dir({ unsafeCleanup: true }); | ||
|
||
let emberCliArgs = [ | ||
'new', | ||
name, | ||
'-b', | ||
blueprintPath, | ||
'--pnpm', | ||
'--skip-git', | ||
...flags, | ||
]; | ||
|
||
await execa(emberCli, emberCliArgs, { | ||
cwd: tmpDir.path, | ||
preferLocal: true, | ||
}); | ||
|
||
// apply the fixture on top of the generated app | ||
copyWithTemplate(join(__dirname, 'fixture'), join(tmpDir.path, name), { | ||
name, | ||
}); | ||
|
||
// Sync the lints for the fixtures with the project's config | ||
await execa(`pnpm`, ['lint:fix'], { | ||
cwd: join(tmpDir.path, name), | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
try { | ||
await tmpDir.cleanup(); | ||
} catch { | ||
// if it fails to cleaup we don't want to break CI | ||
} | ||
}); | ||
|
||
return { | ||
tmpDir: () => tmpDir.path, | ||
appName: () => name, | ||
dir: () => join(tmpDir.path, name), | ||
$: (...args) => execa({ cwd: join(tmpDir.path, name) })(...args), | ||
execa: (program, args, options = {}) => | ||
execa(program, args, { | ||
cwd: join(tmpDir.path, name), | ||
...options, | ||
}), | ||
}; | ||
} |