Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/node_modules/
.log/
/my-addon/
my-addon/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.md
files/
tests/fixtures/
my-addon/

node_modules/

3 changes: 3 additions & 0 deletions files/gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ ember-cli-build.cjs
node_modules/
.eslintcache
.prettiercache

# potentially containing secrets
*.local
2 changes: 1 addition & 1 deletion files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@embroider/addon-dev": "^8.1.0",
"@embroider/compat": "^4.1.0",
"@embroider/core": "^4.1.0",
"@embroider/macros": "^1.18.0",
"@embroider/macros": "^1.20.1",
"@embroider/vite": "^1.1.5",
"@eslint/js": "^9.17.0",
"@glimmer/component": "^2.0.0<% if (typescript) { %>",
Expand Down
2 changes: 2 additions & 0 deletions files/tests/test-helper.__ext__
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny change!

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start as qunitStart, setupEmberOnerrorValidation } from 'ember-qunit';
import { setTesting } from '@embroider/macros';

class Router extends EmberRouter {
location = 'none';
Expand All @@ -21,6 +22,7 @@ class TestApp extends EmberApp {
Router.map(function () {});

export function start() {
setTesting(true);
setApplication(
TestApp.create({
autoboot: false,
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions tests/fixtures/build-mode-tests/debug-utils-test.js
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([]);
});
});
});
20 changes: 20 additions & 0 deletions tests/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ export async function createTmp() {
return tmpDirPath;
}

/**
* Returns a copy of the current process env with EMBER_, VITE_, and NODE_
* prefixed vars removed.
*
* Useful when spawning child processes with `extendEnv: false` so that
* vitest's NODE_ENV=test (and similar) doesn't leak into the child and
* interfere with the build-time / runtime macro mode detection.
*/
export function safeExecaEnv(): Record<string, string | undefined> {
let env = { ...process.env };

for (let key of Object.keys(env)) {
if (key.startsWith('EMBER_') || key.startsWith('VITE_') || key.startsWith('NODE_')) {
delete env[key];
}
}

return env;
}

/**
* Abstraction for install, as the blueprint supports multiple package managers
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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",
Expand Down
9 changes: 6 additions & 3 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { beforeAll, beforeEach, describe, expect, it } from 'vitest';

import {
assertGeneratedCorrectly,
dirContents,
filesMatching,
SUPPORTED_PACKAGE_MANAGERS,
safeExecaEnv,
} from '../helpers.js';
const blueprintPath = path.join(__dirname, '../..');
let localEmberCli = require.resolve('ember-cli/bin/ember');
Expand All @@ -25,6 +25,8 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
cwd: addonDir,
shell: true,
preferLocal: true,
extendEnv: false,
env: safeExecaEnv(),
// Allows us to not fail yet when the command fails
// but we'd still fail appropriately with the exitCode check below.
// When we fail, we want to check for git diffs for debugging purposes.
Expand All @@ -50,13 +52,14 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
addonDir = join(tmpDir, addonName);
await execa({
cwd: tmpDir,
extendEnv: false,
})`${localEmberCli} addon ${addonName} -b ${blueprintPath} --skip-npm --prefer-local true --${packageManager} --typescript`;
// Have to use --force because NPM is *stricter* when you use tags in package.json
// than pnpm (in that tags don't match any specified stable version)
if (packageManager === 'npm') {
await execa({ cwd: addonDir })`npm install --force`;
await execa({ cwd: addonDir, extendEnv: false })`npm install --force`;
} else if (packageManager === 'pnpm') {
await execa({ cwd: addonDir })`pnpm install`;
await execa({ cwd: addonDir, extendEnv: false })`pnpm install`;
}
});

Expand Down
43 changes: 35 additions & 8 deletions tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
dirContents,
matchesFixture,
packageJsonAt,
safeExecaEnv,
SUPPORTED_PACKAGE_MANAGERS,
} from '../helpers.js';
import { existsSync } from 'node:fs';
Expand All @@ -38,8 +39,9 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
addonDir = join(tmpDir, addonName);
await execa({
cwd: tmpDir,
extendEnv: false,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendEnv is noise in this PR without an accompanying env: {} to set the env to empty

})`${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 () => {
Expand Down Expand Up @@ -99,13 +101,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);
});
Expand All @@ -124,16 +129,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);

Expand All @@ -146,13 +162,24 @@ 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 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: safeExecaEnv(),
})`${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
Expand Down
2 changes: 1 addition & 1 deletion tests/smoke-tests/try-scenarios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('try-scenarios', () => {
let addonDir = join(tmpDir, addonName);

function runInAddon(command: string) {
const env = { ...scenario.env };
const env = { ...scenario.env, NODE_ENV: 'development' };
console.log(`Running \`${command}\` with ${JSON.stringify(env)}`);
return execa({ shell: true, preferLocal: true, cwd: addonDir, env })(command);
}
Expand Down
Loading