Skip to content
Open
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/

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

# potentially containing secrets
.env
.env.*.local
10 changes: 10 additions & 0 deletions files/tests/test-helper.__ext__
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start as qunitStart, setupEmberOnerrorValidation } from 'ember-qunit';
<% if (typescript) { %>// @ts-expect-error @embroider/macros does not provide types
<% } %>import { getGlobalConfig } from '@embroider/macros/src/addon/runtime';

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

export function start() {
<% if (typescript) { %>// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
<% } %>const theMacrosGlobal = getGlobalConfig();

<% if (typescript) { %>// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
<% } %>theMacrosGlobal['@embroider/macros'] ||= {};
<% if (typescript) { %>// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
<% } %>theMacrosGlobal['@embroider/macros'].isTesting ||= 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([]);
});
});
});
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
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
63 changes: 29 additions & 34 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import fixturify from 'fixturify';
import { execa } from 'execa';
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';

import {
assertGeneratedCorrectly,
dirContents,
filesMatching,
SUPPORTED_PACKAGE_MANAGERS,
} from '../helpers.js';
import { assertGeneratedCorrectly, filesMatching, SUPPORTED_PACKAGE_MANAGERS } from '../helpers.js';
const blueprintPath = path.join(__dirname, '../..');
let localEmberCli = require.resolve('ember-cli/bin/ember');

Expand Down Expand Up @@ -92,56 +87,56 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
await commandSucceeds(`${packageManager} run build`);

expect(
await filesMatching('src/**', addonDir),
(await filesMatching('src/**', addonDir)).sort(),
`ensure we don't pollute the src dir with declarations and emit the js and .d.ts to the correct folders -- this should be the same as the input files (no change from the fixture + default files)`,
).toMatchInlineSnapshot(`
[
"src/components/another-gts.gts",
"src/components/template-import.gts",
"src/index.ts",
"src/lint-test-gts.gts",
"src/lint-test-ts.ts",
"src/template-registry.ts",
"src/components/another-gts.gts",
"src/components/template-import.gts",
"src/services/example.ts",
"src/template-registry.ts",
]
`);

expect(
await filesMatching('{dist,declarations}/**/*', addonDir),
(await filesMatching('{dist,declarations}/**/*', addonDir)).sort(),
`ensure we emit the correct files out of the box to the correct folders`,
).toMatchInlineSnapshot(`
[
"dist/index.js",
"dist/index.js.map",
"dist/lint-test-gts.js",
"dist/lint-test-gts.js.map",
"dist/lint-test-ts.js",
"dist/lint-test-ts.js.map",
"dist/template-registry.js",
"dist/template-registry.js.map",
"dist/components/another-gts.js",
"dist/components/another-gts.js.map",
"dist/components/template-import.js",
"dist/components/template-import.js.map",
"dist/services/example.js",
"dist/services/example.js.map",
"dist/_app_/components/another-gts.js",
"dist/_app_/components/template-import.js",
"dist/_app_/services/example.js",
"declarations/components/another-gts.d.ts",
"declarations/components/another-gts.d.ts.map",
"declarations/components/template-import.d.ts",
"declarations/components/template-import.d.ts.map",
"declarations/index.d.ts",
"declarations/index.d.ts.map",
"declarations/lint-test-gts.d.ts",
"declarations/lint-test-gts.d.ts.map",
"declarations/lint-test-ts.d.ts",
"declarations/lint-test-ts.d.ts.map",
"declarations/template-registry.d.ts",
"declarations/template-registry.d.ts.map",
"declarations/components/another-gts.d.ts",
"declarations/components/another-gts.d.ts.map",
"declarations/components/template-import.d.ts",
"declarations/components/template-import.d.ts.map",
"declarations/services/example.d.ts",
"declarations/services/example.d.ts.map",
"declarations/template-registry.d.ts",
"declarations/template-registry.d.ts.map",
"dist/_app_/components/another-gts.js",
"dist/_app_/components/template-import.js",
"dist/_app_/services/example.js",
"dist/components/another-gts.js",
"dist/components/another-gts.js.map",
"dist/components/template-import.js",
"dist/components/template-import.js.map",
"dist/index.js",
"dist/index.js.map",
"dist/lint-test-gts.js",
"dist/lint-test-gts.js.map",
"dist/lint-test-ts.js",
"dist/lint-test-ts.js.map",
"dist/services/example.js",
"dist/services/example.js.map",
"dist/template-registry.js",
"dist/template-registry.js.map",
]
`);
});
Expand Down
49 changes: 41 additions & 8 deletions tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
addonDir = join(tmpDir, addonName);
await execa({
cwd: tmpDir,
extendEnv: false,
Copy link
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 +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);
});
Expand All @@ -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);

Expand All @@ -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
Expand Down