From c9f718ce9551d74213088282850b0186460ba1b8 Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Fri, 22 Mar 2024 16:19:19 +0100 Subject: [PATCH] add v1 addon test with co-located component --- tests/scenarios/package.json | 2 +- tests/scenarios/vite-app-test.ts | 84 ++++++++++++++++++- .../tests/integration/example-test.js | 2 +- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/tests/scenarios/package.json b/tests/scenarios/package.json index 305f43b86..733ed7374 100644 --- a/tests/scenarios/package.json +++ b/tests/scenarios/package.json @@ -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" }, diff --git a/tests/scenarios/vite-app-test.ts b/tests/scenarios/vite-app-test.ts index 094303556..d0ca5ef92 100644 --- a/tests/scenarios/vite-app-test.ts +++ b/tests/scenarios/vite-app-test.ts @@ -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; @@ -24,7 +25,88 @@ function execPromise(command: string): Promise { 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\` + + \`); + await rerender(); + assert.dom().includesText('component one template'); + assert.dom().doesNotIncludeText('export default precompileTemplate'); + }); + }); + + `, + }, + }, app: { adapters: { 'post.js': ` diff --git a/tests/vite-app/tests/integration/example-test.js b/tests/vite-app/tests/integration/example-test.js index fd96f7c80..5a4ea1416 100644 --- a/tests/vite-app/tests/integration/example-test.js +++ b/tests/vite-app/tests/integration/example-test.js @@ -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) => {