From 23c8508f490072f398d40cefc6b2431e20861ed2 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Wed, 13 Nov 2024 12:18:57 -0500 Subject: [PATCH] refactoring a test that came across from stable to main --- tests/scenarios/compat-stage2-test.ts | 81 --------------------------- tests/scenarios/stage1-test.ts | 69 +++++++++++++++++++++++ 2 files changed, 69 insertions(+), 81 deletions(-) diff --git a/tests/scenarios/compat-stage2-test.ts b/tests/scenarios/compat-stage2-test.ts index c3355c023..1ae156e8e 100644 --- a/tests/scenarios/compat-stage2-test.ts +++ b/tests/scenarios/compat-stage2-test.ts @@ -8,7 +8,6 @@ import { throwOnWarnings } from '@embroider/core'; import merge from 'lodash/merge'; import QUnit from 'qunit'; import { readJsonSync, writeJsonSync } from 'fs-extra'; -import { setupAuditTest } from '@embroider/test-support/audit-assertions'; const { module: Qmodule, test } = QUnit; @@ -277,86 +276,6 @@ stage2Scenarios }); }); -stage2Scenarios - .map('gts-files-in-addons-are-pre-processed-with-template-compilation', app => { - let depA = addAddon(app, 'dep-a'); - depA.linkDependency('ember-template-imports', { baseDir: __dirname }); - depA.linkDependency('ember-cli-babel', { baseDir: __dirname, resolveName: 'ember-cli-babel-latest' }); - - merge(depA.files, { - 'index.js': ` - 'use strict'; - module.exports = { - name: require('./package').name, - options: { - 'ember-cli-babel': { enableTypeScriptTransform: true }, - }, - };`, - addon: { - components: { - 'other.gts': ` - import Component from '@glimmer/component'; - - export default class extends Component { - abc: string; - - }; - `, - 'gts-component.gts': ` - import Component from '@glimmer/component'; - import OtherComponent from './other'; - - export default class extends Component { - abc: string; - - }; - `, - }, - }, - app: { - components: { - 'gts-component.js': 'export { default } from "dep-a/components/gts-component"', - }, - }, - }); - }) - .forEachScenario(scenario => { - Qmodule(scenario.name, function (hooks) { - throwOnWarnings(hooks); - - let app: PreparedApp; - - hooks.before(async assert => { - app = await scenario.prepare(); - let result = await app.execute('ember build', { env: { STAGE2_ONLY: 'true' } }); - assert.equal(result.exitCode, 0, result.output); - }); - - let expectAudit = setupAuditTest(hooks, () => ({ app: app.dir, 'reuse-build': true })); - - test('no audit issues', function () { - expectAudit.hasNoFindings(); - }); - - test('gts is processed with template-compilation', function () { - let expectModule = expectAudit.module('./assets/my-app.js'); - // this is to make sure that the babel plugin template compilation runs and thus - // make imports that are only used in templates bound and not removed by typescript - expectModule - .resolves('my-app/components/gts-component.js') - .toModule() - .resolves('dep-a/components/gts-component') - .toModule() - .codeContains(`import OtherComponent from './other';`); - }); - }); - }); - dummyAppScenarios .skip() .map('compat-stage2-addon-dummy-app', app => { diff --git a/tests/scenarios/stage1-test.ts b/tests/scenarios/stage1-test.ts index 62a319d61..9e801f479 100644 --- a/tests/scenarios/stage1-test.ts +++ b/tests/scenarios/stage1-test.ts @@ -50,6 +50,55 @@ appScenarios // our app will include an in-repo addon project.pkg['ember-addon'] = { paths: ['lib/in-repo-addon'] }; merge(project.files, loadFromFixtureData('basic-in-repo-addon')); + + let addonWithGTS = baseAddon(); + addonWithGTS.pkg.name = 'addon-with-gts'; + addonWithGTS.linkDependency('ember-template-imports', { baseDir: __dirname }); + addonWithGTS.linkDependency('ember-cli-babel', { baseDir: __dirname, resolveName: 'ember-cli-babel-latest' }); + addonWithGTS.mergeFiles({ + 'index.js': ` + 'use strict'; + module.exports = { + name: require('./package').name, + options: { + 'ember-cli-babel': { enableTypeScriptTransform: true }, + }, + };`, + addon: { + components: { + 'other.gts': ` + import Component from '@glimmer/component'; + + export default class extends Component { + abc: string; + + }; + `, + 'gts-component.gts': ` + import Component from '@glimmer/component'; + import OtherComponent from './other'; + + export default class extends Component { + get abc(): string { + return 'abs'; + } + + }; + `, + }, + }, + app: { + components: { + 'gts-component.js': 'export { default } from "addon-with-gts/components/gts-component"', + }, + }, + }); + project.addDependency(addonWithGTS); }) .forEachScenario(async scenario => { Qmodule(`${scenario.name}`, function (hooks) { @@ -159,6 +208,26 @@ appScenarios /return import\(['"]some-library['"]\)/ ); }); + + test('gts in addons has valid imports', function () { + expectFile('node_modules/addon-with-gts/components/gts-component.js').equalsCode(` + import Component from '@glimmer/component'; + import OtherComponent from './other'; + import { precompileTemplate } from "@ember/template-compilation"; + import { setComponentTemplate } from "@ember/component"; + export default class _Class extends Component { + get abc() { + return 'abs'; + } + } + setComponentTemplate(precompileTemplate("\\n this is gts\\n with \\n ", { + strictMode: true, + scope: () => ({ + OtherComponent + }) + }), _Class); + `); + }); }); });