diff --git a/packages/compat/src/compat-app-builder.ts b/packages/compat/src/compat-app-builder.ts index 32de08e87..3cf10a4c3 100644 --- a/packages/compat/src/compat-app-builder.ts +++ b/packages/compat/src/compat-app-builder.ts @@ -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'; @@ -86,15 +85,6 @@ export class CompatAppBuilder { private extractAssets(treePaths: OutputPaths): 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); } @@ -102,24 +92,6 @@ export class CompatAppBuilder { 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 diff --git a/packages/compat/src/compat-app.ts b/packages/compat/src/compat-app.ts index 499f6c8e7..d2226e91f 100644 --- a/packages/compat/src/compat-app.ts +++ b/packages/compat/src/compat-app.ts @@ -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'; @@ -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: + * + * 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 = {