Skip to content

Commit

Permalink
don't include runtime conditional if we don't have a test tree
Browse files Browse the repository at this point in the history
  • Loading branch information
22a committed Jun 7, 2023
1 parent 2949e9b commit d61234f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
20 changes: 12 additions & 8 deletions packages/compat/src/v1-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ export class WriteV1Config extends Plugin {
if (this.storeConfigInMeta) {
contents = metaLoader();
} else {
contents = `
import { isTesting } from '@embroider/macros';
let env;
if (isTesting()) {
env = ${JSON.stringify(this.testInputTree?.readConfig())};
if (this.testInputTree) {
contents = `
import { isTesting } from '@embroider/macros';
let env;
if (isTesting()) {
env = ${JSON.stringify(this.testInputTree.readConfig())};
} else {
env = ${JSON.stringify(this.inputTree.readConfig())};
}
export default env;
`;
} else {
env = ${JSON.stringify(this.inputTree.readConfig())};
contents = `export default ${JSON.stringify(this.inputTree.readConfig())};`;
}
export default env;
`;
}
if (!this.lastContents || this.lastContents !== contents) {
outputFileSync(filename, contents);
Expand Down
20 changes: 14 additions & 6 deletions tests/scenarios/app-config-environment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ appScenarios
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
// CUSTOM
ENV.someCustomField = true;
};
// CUSTOM
ENV.someCustomField = true;
return ENV;
};`,
},
Expand All @@ -57,7 +58,7 @@ appScenarios
import { module, test } from 'qunit';
import ENV from 'app-template/config/environment';
module('Unit | storeConfigInMeta', function (hooks) {
module('Unit | storeConfigInMeta set to false', function (hooks) {
test('it has loaded the correct config values', async function (assert) {
assert.equal(ENV.someCustomField, true);
});
Expand All @@ -73,9 +74,16 @@ appScenarios
app = await scenario.prepare();
});

test(`yarn test ran with custom unit test`, async function (assert) {
let result = await app.execute(`yarn test`);
assert.equal(result.exitCode, 0, result.output);
test(`ember test ran against dev build with custom unit test`, async function (assert) {
// here we build the app with environment set to dev so that we can use
// the build output directory as the input path to an `ember test` run
// later. This difference in environment is important because it's the
// only way for us to test ember-cli-build.js' `tests: true` behavior,
// and is equivalent to visiting the app's /tests page
let devBuildResult = await app.execute(`pnpm build --environment=development`);
assert.equal(devBuildResult.exitCode, 0, devBuildResult.output);
let testRunResult = await app.execute(`pnpm test:ember --path dist`);
assert.equal(testRunResult.exitCode, 0, testRunResult.output);
});
});
});

0 comments on commit d61234f

Please sign in to comment.