Skip to content

Commit

Permalink
Merge pull request #1923 from embroider-build/testem-asset
Browse files Browse the repository at this point in the history
Move testem support out of rewritten app
  • Loading branch information
mansona committed May 16, 2024
2 parents f469b9f + 4907782 commit c8b5bd4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
28 changes: 0 additions & 28 deletions packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { activePackageRules } from './dependency-rules';
import flatMap from 'lodash/flatMap';
import mergeWith from 'lodash/mergeWith';
import cloneDeep from 'lodash/cloneDeep';
import { sync as resolveSync } from 'resolve';
import bind from 'bind-decorator';
import { outputJSONSync, readJSONSync, rmSync, statSync, unlinkSync, writeFileSync, realpathSync } from 'fs-extra';
import type { Options as EtcOptions } from 'babel-plugin-ember-template-compilation';
Expand Down Expand Up @@ -86,40 +85,13 @@ export class CompatAppBuilder {
private extractAssets(treePaths: OutputPaths<TreeNames>): Asset[] {
let assets: Asset[] = [];

// ember-cli traditionally outputs a dummy testem.js file to prevent
// spurious errors when running tests under "ember s".
if (this.compatApp.shouldBuildTests) {
let testemAsset = this.findTestemAsset();
if (testemAsset) {
assets.push(testemAsset);
}
}

for (let asset of this.emberEntrypoints(treePaths.htmlTree)) {
assets.push(asset);
}

return assets;
}

@Memoize()
private findTestemAsset(): Asset | undefined {
let sourcePath;
try {
sourcePath = resolveSync('ember-cli/lib/broccoli/testem.js', { basedir: this.root });
} catch (err) {}
if (sourcePath) {
let stat = statSync(sourcePath);
return {
kind: 'on-disk',
relativePath: 'testem.js',
sourcePath,
mtime: stat.mtime.getTime(),
size: stat.size,
};
}
}

private activeAddonChildren(pkg: Package): AddonPackage[] {
let result = (pkg.dependencies.filter(this.isActiveAddon) as AddonPackage[]).filter(
// When looking for child addons, we want to ignore 'peerDependencies' of
Expand Down
28 changes: 27 additions & 1 deletion packages/compat/src/compat-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ContentForConfig from './content-for-config';
import { V1Config, WriteV1Config } from './v1-config';
import { WriteV1AppBoot, ReadV1AppBoot } from './v1-appboot';
import type { AddonMeta, EmberAppInstance, OutputFileToInputFileMap, PackageInfo } from '@embroider/core';
import { writeJSONSync, ensureDirSync, copySync, pathExistsSync, existsSync } from 'fs-extra';
import { writeJSONSync, ensureDirSync, copySync, pathExistsSync, existsSync, writeFileSync } from 'fs-extra';
import AddToTree from './add-to-tree';
import DummyPackage from './dummy-package';
import type { TransformOptions } from '@babel/core';
Expand Down Expand Up @@ -454,6 +454,32 @@ export default class CompatApp {
copySync(sourcePath, destPath);
}

if (this.shouldBuildTests) {
writeFileSync(
join(outputPath, 'testem.js'),
`/*
* This is dummy file that exists for the sole purpose
* of allowing tests to run directly in the browser as
* well as by Testem.
*
* Testem is configured to run tests directly against
* the test build of index.html, which requires a
* snippet to load the testem.js file:
* <script src="/testem.js"></script>
* This has to go before the qunit framework and app
* tests are loaded.
*
* Testem internally supplies this file. However, if you
* run the tests directly in the browser (localhost:8000/tests),
* this file does not exist.
*
* Hence the purpose of this fake file. This file is served
* directly from the express server to satisify the script load.
*/`
);
this._publicAssets['/testem.js'] = './testem.js';
}

let remapAsset = this.remapAsset.bind(this);

let addonMeta: AddonMeta = {
Expand Down

0 comments on commit c8b5bd4

Please sign in to comment.