+ I expect to be blue +
+ +); \ No newline at end of file diff --git a/tests/fixture-ts/testem-proxy.js b/tests/fixture-ts/testem-proxy.js new file mode 100644 index 0000000..d688f53 --- /dev/null +++ b/tests/fixture-ts/testem-proxy.js @@ -0,0 +1,36 @@ +/* eslint-disable */ +const httpProxy = require('http-proxy'); + +/* + This can be installed as a testem middleware to make testem run against an + arbitrary real webserver at targetURL. + + It allows testem to handle the well-known testem-specific paths and proxies + everything else, while rewriting the testem-added prefix out of your + "/tests/index.html" URL. +*/ + +module.exports = function testemProxy(targetURL) { + return function testemProxyHandler(app) { + const proxy = httpProxy.createProxyServer({ + changeOrigin: true, + ignorePath: true, + }); + + proxy.on('error', (err, _req, res) => { + res && res.status && res.status(500).json(err); + }); + + app.all('*', (req, res, next) => { + let url = req.url; + if (url === '/testem.js' || url.startsWith('/testem/')) { + return next(); + } + let m = /^(\/\d+)\/tests\/index.html/.exec(url); + if (m) { + url = url.slice(m[1].length); + } + proxy.web(req, res, { target: targetURL + url }); + }); + }; +}; diff --git a/tests/fixture-ts/tests/acceptance/app-init-test.ts b/tests/fixture-ts/tests/acceptance/app-init-test.ts new file mode 100644 index 0000000..e65bc63 --- /dev/null +++ b/tests/fixture-ts/tests/acceptance/app-init-test.ts @@ -0,0 +1,22 @@ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { module, test } from 'qunit'; +import { getApplication } from '@ember/test-helpers'; +import { assert as debugAssert } from '@ember/debug'; +import { setupApplicationTest } from '<%= name %>/tests/helpers'; + +module('Acceptance | app route', function (hooks) { + setupApplicationTest(hooks); + + test('loaded initializers /', function (assert) { + const app = getApplication(); + + debugAssert(`App failed to initialize`, app); + + assert.strictEqual( + ([...app._applicationInstances][0] as any).__instance_test_init, + 'set in the instance initializer', + ); + assert.strictEqual((app as any).__test_init, 'coming from the initializer'); + }); +}); diff --git a/tests/fixture-ts/tests/acceptance/custom-component-test.ts b/tests/fixture-ts/tests/acceptance/custom-component-test.ts new file mode 100644 index 0000000..24e6db0 --- /dev/null +++ b/tests/fixture-ts/tests/acceptance/custom-component-test.ts @@ -0,0 +1,14 @@ +import { module, test } from 'qunit'; +import { visit, currentURL } from '@ember/test-helpers'; +import { setupApplicationTest } from '<%= name %>/tests/helpers'; + +module('Acceptance | custom-component page', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /custom-component', async function (assert) { + await visit('/custom-component'); + + assert.strictEqual(currentURL(), '/custom-component'); + assert.dom('#custom-component').containsText('I am a custom component'); + }); +}) diff --git a/tests/fixture-ts/tests/acceptance/styles-test.ts b/tests/fixture-ts/tests/acceptance/styles-test.ts new file mode 100644 index 0000000..00169a5 --- /dev/null +++ b/tests/fixture-ts/tests/acceptance/styles-test.ts @@ -0,0 +1,18 @@ +import { module, test } from 'qunit'; +import { visit } from '@ember/test-helpers'; +import { setupApplicationTest } from '<%= name %>/tests/helpers'; + +module('Acceptance | styles', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /styles', async function (assert) { + await visit('/styles'); + + assert.dom('.styles-test').hasStyle( + { + 'background-color': 'rgb(0, 0, 255)', + }, + 'The background should be blue if the app styles are working correctly', + ); + }); +}); diff --git a/tests/fixture-ts/tests/acceptance/welcome-page-test.ts b/tests/fixture-ts/tests/acceptance/welcome-page-test.ts new file mode 100644 index 0000000..0ace2f3 --- /dev/null +++ b/tests/fixture-ts/tests/acceptance/welcome-page-test.ts @@ -0,0 +1,14 @@ +import { module, test } from 'qunit'; +import { visit, currentURL } from '@ember/test-helpers'; +import { setupApplicationTest } from '<%= name %>/tests/helpers'; + +module('Acceptance | welcome page', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /index shows the welcome page', async function (assert) { + await visit('/'); + + assert.strictEqual(currentURL(), '/'); + assert.dom('h1').containsText('Congratulations, you made it!'); + }); +}); diff --git a/tests/fixture/app/router.ts b/tests/fixture/app/router.ts new file mode 100644 index 0000000..8a5b048 --- /dev/null +++ b/tests/fixture/app/router.ts @@ -0,0 +1,12 @@ +import EmberRouter from '@ember/routing/router'; +import config from '<%= name %>/config/environment'; + +export default class Router extends EmberRouter { + location = config.locationType; + rootURL = config.rootURL; +} + +Router.map(function () { + this.route('styles'); + this.route('custom-component'); +}); diff --git a/tests/typescript.test.mjs b/tests/typescript.test.mjs new file mode 100644 index 0000000..e308cc0 --- /dev/null +++ b/tests/typescript.test.mjs @@ -0,0 +1,24 @@ +import { describe, it, expect } from 'vitest'; +import { join } from 'path'; +import { existsSync } from 'fs'; +import { newProjectWithFixtures } from './helpers.mjs'; + +describe('typescript', function () { + let project = newProjectWithFixtures({ + fixturePath: join(__dirname, 'fixture-ts'), + flags: ['--typescript'], + }); + + it('verify files', async function () { + expect( + existsSync(join(project.dir(), 'tsconfig.json')), + 'the root tsconfig.json has been added', + ); + }); + + it('glint passes', async function () { + let result = await project.execa('pnpm', ['glint']); + + console.log(result.stdout); + }); +});