Skip to content

Commit

Permalink
Test that co-located and template-only components compile and can be …
Browse files Browse the repository at this point in the history
…used by the test-app
  • Loading branch information
NullVoxPopuli committed Jul 17, 2023
1 parent 7798063 commit 61bcb5e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
37 changes: 21 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Rendering | co-located', function(hooks) {
setupRenderingTest(hooks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Rendering | template-only', function(hooks) {
setupRenderingTest(hooks);
Expand Down
67 changes: 31 additions & 36 deletions tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
import fse from 'fs-extra';
import fs from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import {
AddonHelper,
assertGeneratedCorrectly,
createAddon,
createTmp,
dirContents,
install,
runScript,
SUPPORTED_PACKAGE_MANAGERS,
} from '../helpers.js';

for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
describe(`defaults with ${packageManager}`, () => {
let cwd = '';
let tmpDir = '';
let distDir = '';
let helper = new AddonHelper({ packageManager });

beforeAll(async () => {
tmpDir = await createTmp();
await helper.setup();
await helper.installDeps({ skipPrepare: false });

console.debug(`Debug test repo at ${tmpDir}`);

let { name } = await createAddon({
args: [`--${packageManager}=true`],
options: { cwd: tmpDir },
});

cwd = path.join(tmpDir, name);
distDir = path.join(cwd, name, 'dist');

await install({ cwd, packageManager });
distDir = path.join(helper.addonFolder, 'dist');
});

afterAll(async () => {
fs.rm(tmpDir, { recursive: true, force: true });
await helper.clean();
});

it('is using the correct packager', async () => {
let npm = path.join(cwd, 'package-lock.json');
let yarn = path.join(cwd, 'yarn.lock');
let pnpm = path.join(cwd, 'pnpm-lock.yaml');
let npm = path.join(helper.projectRoot, 'package-lock.json');
let yarn = path.join(helper.projectRoot, 'yarn.lock');
let pnpm = path.join(helper.projectRoot, 'pnpm-lock.yaml');

switch (packageManager) {
case 'npm': {
Expand Down Expand Up @@ -79,29 +65,38 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
});

it('was generated correctly', async () => {
assertGeneratedCorrectly({ projectRoot: cwd });
assertGeneratedCorrectly({ projectRoot: helper.projectRoot });
});

it('builds the addon', async () => {
let { exitCode } = await runScript({ cwd, script: 'build', packageManager });
// Tests are additive, so when running them in order, we want to check linting
// before we add files from fixtures
it('lints all pass', async () => {
let { exitCode } = await helper.run('lint');

expect(exitCode).toEqual(0);
});

let contents = await dirContents(distDir);
it('build and test ', async () => {
// Copy over fixtures
await helper.fixtures.use('./my-addon/src/components');
await helper.fixtures.use('./test-app/tests');
// Sync fixture with project's lint / formatting configuration
await helper.run('lint:fix');

expect(contents).to.deep.equal(['index.js', 'index.js.map']);
});
let buildResult = await helper.build();

it('runs tests', async () => {
let { exitCode } = await runScript({ cwd, script: 'test', packageManager });
expect(buildResult.exitCode).toEqual(0);

expect(exitCode).toEqual(0);
});
let contents = await dirContents(distDir);

it('lints all pass', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager });
expect(contents).to.deep.equal(['_app_', 'components', 'index.js', 'index.js.map']);

expect(exitCode).toEqual(0);
let testResult = await helper.run('test');

expect(testResult.exitCode).toEqual(0);
expect(testResult.stdout).to.include('# tests 3');
expect(testResult.stdout).to.include('# pass 3');
expect(testResult.stdout).to.include('# fail 0');
});
});
}

0 comments on commit 61bcb5e

Please sign in to comment.