Skip to content

Commit

Permalink
refactoring a test that came across from stable to main
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Nov 13, 2024
1 parent 969ad09 commit 23c8508
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 81 deletions.
81 changes: 0 additions & 81 deletions tests/scenarios/compat-stage2-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
<template>
other
</template>
};
`,
'gts-component.gts': `
import Component from '@glimmer/component';
import OtherComponent from './other';
export default class extends Component {
abc: string;
<template>
this is gts
with <OtherComponent />
</template>
};
`,
},
},
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 => {
Expand Down
69 changes: 69 additions & 0 deletions tests/scenarios/stage1-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
<template>
other
</template>
};
`,
'gts-component.gts': `
import Component from '@glimmer/component';
import OtherComponent from './other';
export default class extends Component {
get abc(): string {
return 'abs';
}
<template>
this is gts
with <OtherComponent />
</template>
};
`,
},
},
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) {
Expand Down Expand Up @@ -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 <OtherComponent />\\n ", {
strictMode: true,
scope: () => ({
OtherComponent
})
}), _Class);
`);
});
});
});

Expand Down

0 comments on commit 23c8508

Please sign in to comment.