Skip to content

Commit

Permalink
add v1 addon test with co-located component
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Mar 22, 2024
1 parent bac2415 commit c9f718c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ts-node": "^10.9.1"
},
"scripts": {
"test": "qunit --require ts-node/register *-test.ts",
"test": "qunit --require ts-node/register *-test.ts --filter vite",
"test:list": "scenario-tester list --require ts-node/register --files=*-test.ts",
"test:output": "scenario-tester output --require ts-node/register --files=*-test.ts"
},
Expand Down
84 changes: 83 additions & 1 deletion tests/scenarios/vite-app-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { viteAppScenarios } from './scenarios';
import { baseAddon, viteAppScenarios } from './scenarios';
import type { PreparedApp } from 'scenario-tester';
import QUnit from 'qunit';
import { exec } from 'child_process';
import { readdirSync } from 'fs-extra';
import { join } from 'path';
import { merge } from 'lodash';

const { module: Qmodule, test } = QUnit;

Expand All @@ -24,7 +25,88 @@ function execPromise(command: string): Promise<string> {

viteAppScenarios
.map('vite-app-basics', project => {
let addon = baseAddon();
addon.pkg.name = 'my-addon';
// setup addon that triggers packages/compat/src/hbs-to-js-broccoli-plugin.ts
merge(addon.files, {
'index.js': `
module.exports = {
name: 'my-addon',
setupPreprocessorRegistry(type, registry) {
// we want custom ast transforms for own addon
if (type === 'parent') {
return;
}
const plugin = this._buildPlugin();
plugin.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', plugin);
},
_buildPlugin(options) {
return {
name: 'test-transform',
plugin: () => {
return {
name: "test-transform",
visitor: {
Template() {}
},
};
},
baseDir() {
return __dirname;
},
};
},
}
`,
app: {
components: {
'component-one.js': `export { default } from 'my-addon/components/component-one';`,
},
},
addon: {
components: {
'component-one.js': `
import Component from '@glimmer/component';
export default class ComponentOne extends Component {}
`,
'component-one.hbs': `component one template`,
},
},
});

project.addDevDependency(addon);
project.mergeFiles({
tests: {
integration: {
'test-colocated-addon-component.js': `
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, rerender } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | component one template from addon', (hooks) => {
setupRenderingTest(hooks);
test('should have component one template from addon', async function (assert) {
await render(hbs\`
<ComponentOne></ComponentOne>
\`);
await rerender();
assert.dom().includesText('component one template');
assert.dom().doesNotIncludeText('export default precompileTemplate');
});
});
`,
},
},
app: {
adapters: {
'post.js': `
Expand Down
2 changes: 1 addition & 1 deletion tests/vite-app/tests/integration/example-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, rerender, settled } from '@ember/test-helpers';
import { render, rerender } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | Example', (hooks) => {
Expand Down

0 comments on commit c9f718c

Please sign in to comment.