-
-
Notifications
You must be signed in to change notification settings - Fork 9
Add build mode tests (ensuring isDevelopingApp and isTesting are appropriately true when they need to be (as well as assert-stripping)) #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| /node_modules/ | ||
| .log/ | ||
| /my-addon/ | ||
| my-addon/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| *.md | ||
| files/ | ||
| tests/fixtures/ | ||
| my-addon/ | ||
|
|
||
| node_modules/ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { test, module } from 'qunit'; | ||
| import { assert } from '@ember/debug'; | ||
| import { DEBUG } from '@glimmer/env'; | ||
| import { isDevelopingApp, isTesting } from '@embroider/macros'; | ||
|
|
||
| module('debug utils remain in the build', function () { | ||
| test('assert', function(qAssert) { | ||
| // If we get the build mode wrong, e.g.: `NODE_ENV` != 'development' | ||
| // then the assert won't exist, causing qAssert to not detect a thrown Error | ||
| qAssert.throws(() => { | ||
| assert('should throw'); | ||
| }, /should throw/, `The error "should throw" is thrown`); | ||
| }); | ||
|
|
||
| test('isTesting', function (assert) { | ||
| assert.strictEqual(isTesting(), true, `isTesting() === true`); | ||
| }); | ||
|
|
||
| test('isDevelopingApp', function (assert) { | ||
| assert.strictEqual(isDevelopingApp(), true, `isDevelopingApp() === true`); | ||
| }); | ||
|
|
||
|
|
||
| module('not supported', function () { | ||
| test('DEBUG', function (assert) { | ||
| if (DEBUG) { | ||
| assert.step('DEBUG'); | ||
| } | ||
|
|
||
| assert.verifySteps([]); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| "@vitest/ui": "^0.18.0", | ||
| "c8": "^7.11.3", | ||
| "ember-cli": "github:ember-cli/ember-cli#master", | ||
| "execa": "^9.5.2", | ||
| "execa": "^9.6.0", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be PR'd separately |
||
| "fixturify": "^3.0.0", | ||
| "fs-extra": "^10.0.0", | ||
| "globby": "^14.1.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,8 +38,9 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | |
| addonDir = join(tmpDir, addonName); | ||
| await execa({ | ||
| cwd: tmpDir, | ||
| extendEnv: false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extendEnv is noise in this PR without an accompanying |
||
| })`${localEmberCli} addon ${addonName} -b ${blueprintPath} --skip-npm --skip-git --prefer-local true --${packageManager}`; | ||
| await execa({ cwd: addonDir })`${packageManager} install`; | ||
| await execa({ cwd: addonDir, extendEnv: false })`${packageManager} install`; | ||
| }); | ||
|
|
||
| it('is using the correct packager', async () => { | ||
|
|
@@ -99,13 +100,16 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | |
| // Tests are additive, so when running them in order, we want to check linting | ||
| // before we add files from fixtures | ||
| it('lints with no fixtures all pass', async () => { | ||
| let { exitCode } = await execa({ cwd: addonDir })`pnpm lint`; | ||
| let { exitCode } = await execa({ cwd: addonDir, extendEnv: false })`pnpm lint`; | ||
|
|
||
| expect(exitCode).toEqual(0); | ||
| }); | ||
|
|
||
| it('lint:fix with no fixtures', async () => { | ||
| let { exitCode } = await execa({ cwd: addonDir })`${packageManager} run lint:fix`; | ||
| let { exitCode } = await execa({ | ||
| cwd: addonDir, | ||
| extendEnv: false, | ||
| })`${packageManager} run lint:fix`; | ||
|
|
||
| expect(exitCode).toEqual(0); | ||
| }); | ||
|
|
@@ -124,16 +128,27 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | |
|
|
||
| let testFixture = fixturify.readSync('./fixtures/rendering-tests'); | ||
| fixturify.writeSync(join(addonDir, 'tests/rendering'), testFixture); | ||
|
|
||
| fixturify.writeSync( | ||
| join(addonDir, 'tests/unit'), | ||
| fixturify.readSync('./fixtures/build-mode-tests'), | ||
| ); | ||
| }); | ||
|
|
||
| it('lint:fix', async () => { | ||
| let { exitCode } = await execa({ cwd: addonDir })`${packageManager} run lint:fix`; | ||
| let { exitCode } = await execa({ | ||
| cwd: addonDir, | ||
| extendEnv: false, | ||
| })`${packageManager} run lint:fix`; | ||
|
|
||
| expect(exitCode).toEqual(0); | ||
| }); | ||
|
|
||
| it('build', async () => { | ||
| let buildResult = await execa({ cwd: addonDir })`${packageManager} run build`; | ||
| let buildResult = await execa({ | ||
| cwd: addonDir, | ||
| extendEnv: false, | ||
| })`${packageManager} run build`; | ||
|
|
||
| expect(buildResult.exitCode).toEqual(0); | ||
|
|
||
|
|
@@ -146,13 +161,31 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { | |
| // It's important that we ensure that dist directory is empty for this test, because | ||
| await fs.rm(join(addonDir, 'dist'), { recursive: true, force: true }); | ||
|
|
||
| let testResult = await execa({ cwd: addonDir })`${packageManager} run test`; | ||
| let safeEnv = { ...process.env }; | ||
| for (let key of Object.keys(safeEnv)) { | ||
| if (key.startsWith('EMBER_') || key.startsWith('VITE_') || key.startsWith('NODE_')) { | ||
| delete safeEnv[key]; | ||
| } | ||
| } | ||
|
|
||
| let testResult = await execa({ | ||
| cwd: addonDir, | ||
| extendEnv: false, | ||
| // a modified env required with extendEnv, else we still inherit/merge the env of vitest | ||
| // which overrides our NODE_ENV from our .env.development file (read by vite) | ||
| // (because in-shell ENV vars override .env files) | ||
| env: safeEnv, | ||
| })`${packageManager} run test`; | ||
|
|
||
| expect(testResult.exitCode).toEqual(0); | ||
|
|
||
| expect(testResult.stdout).includes('debug utils remain in the build: assert'); | ||
| expect(testResult.stdout).includes( | ||
| 'debug utils remain in the build > not supported: DEBUG', | ||
| ); | ||
| expect(testResult.stdout).includes( | ||
| `# tests 2 | ||
| # pass 2 | ||
| `# tests 6 | ||
| # pass 6 | ||
| # skip 0 | ||
| # todo 0 | ||
| # fail 0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.