Skip to content

Commit

Permalink
Reorganize tests in to multiple files so the tests are less overwhelm…
Browse files Browse the repository at this point in the history
…ing to work with
  • Loading branch information
NullVoxPopuli committed Jul 14, 2023
1 parent f793715 commit be0bbe3
Show file tree
Hide file tree
Showing 9 changed files with 602 additions and 537 deletions.
536 changes: 0 additions & 536 deletions tests/cli.test.ts

This file was deleted.

45 changes: 45 additions & 0 deletions tests/smoke-tests/--addon-location.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { assertGeneratedCorrectly } from '../assertions.js';
import { createAddon, createTmp, install, runScript } from '../utils.js';

describe('--addon-location', () => {
let cwd = '';
let tmpDir = '';
let addonLocation = 'packages/my-custom-location';

beforeAll(async () => {
tmpDir = await createTmp();

let { name } = await createAddon({
args: [`--addon-location=${addonLocation}`, '--pnpm=true'],
options: { cwd: tmpDir },
});

cwd = path.join(tmpDir, name);

await install({ cwd, packageManager: 'pnpm' });
});

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

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

it('runs tests', async () => {
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' });

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

it('lints all pass', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);
});
});
49 changes: 49 additions & 0 deletions tests/smoke-tests/--addon-only.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 { createAddon, createTmp, install, runScript } from '../utils.js';

describe('--addon-only', () => {
let cwd = '';
let tmpDir = '';

beforeAll(async () => {
tmpDir = await createTmp();

let { name } = await createAddon({
args: ['--addon-only', '--pnpm=true'],
options: { cwd: tmpDir },
});

cwd = path.join(tmpDir, name);

await install({ cwd, packageManager: 'pnpm' });
});

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

it('is not a monorepo', async () => {
let hasPnpmWorkspace = await fse.pathExists(path.join(cwd, 'pnpm-workspace.yaml'));
let packageJson = await fse.readJson(path.join(cwd, 'package.json'));

expect(hasPnpmWorkspace).toBe(false);
// Pnpm doesn't use this field, but it's good that it doesn't exist.
expect(packageJson.workspaces).toBeFalsy();
});

it('can build', async () => {
let { exitCode } = await runScript({ cwd, script: 'build', packageManager: 'pnpm' });

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

it('has passing lints', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);
});
});
45 changes: 45 additions & 0 deletions tests/smoke-tests/--test-app-location.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import { assertGeneratedCorrectly } from '../assertions.js';
import { createAddon, createTmp, install, runScript } from '../utils.js';

describe('--test-app-location', () => {
let cwd = '';
let tmpDir = '';
let testAppLocation = 'packages/my-custom-location';

beforeAll(async () => {
tmpDir = await createTmp();

let { name } = await createAddon({
args: [`--test-app-location=${testAppLocation}`, '--pnpm=true'],
options: { cwd: tmpDir },
});

cwd = path.join(tmpDir, name);

await install({ cwd, packageManager: 'pnpm' });
});

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

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

it('runs tests', async () => {
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' });

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

it('lints all pass', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);
});
});
75 changes: 75 additions & 0 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

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

for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
describe(`--typescript with ${packageManager}`, () => {
let cwd = '';
let tmpDir = '';
let distDir = '';

beforeAll(async () => {
tmpDir = await createTmp();

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

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

await install({ cwd, packageManager, skipPrepare: true });
});

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

it('was generated correctly', async () => {
await runScript({ cwd, script: 'build', packageManager: 'pnpm' });

assertGeneratedCorrectly({ projectRoot: cwd });
});

it('builds the addon', async () => {
let { exitCode } = await runScript({ cwd, script: 'build', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);

let contents = await dirContents(distDir);

expect(contents).to.deep.equal([
'index.d.ts',
'index.d.ts.map',
'index.js',
'index.js.map',
'template-registry.d.ts',
'template-registry.js',
'template-registry.js.map',
]);
});

it('runs tests', async () => {
let { exitCode } = await runScript({ cwd, script: 'test', packageManager: 'pnpm' });

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

it('lints all pass', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager: 'pnpm' });

expect(exitCode).toEqual(0);
});
});
}
107 changes: 107 additions & 0 deletions tests/smoke-tests/defaults.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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 { assertGeneratedCorrectly } from '../assertions.js';
import {
createAddon,
createTmp,
dirContents,
install,
runScript,
SUPPORTED_PACKAGE_MANAGERS,
} from '../utils.js';

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

beforeAll(async () => {
tmpDir = await createTmp();

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 });
});

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

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');

switch (packageManager) {
case 'npm': {
expect(await fse.pathExists(npm), 'for NPM: package-lock.json exists').toBe(true);
expect(await fse.pathExists(yarn), 'yarn.lock does not exist').toBe(false);
expect(await fse.pathExists(pnpm), 'pnpm-lock.yaml does not exist').toBe(false);

break;
}
case 'yarn': {
expect(await fse.pathExists(yarn), 'for Yarn: yarn.lock exists').toBe(true);
expect(await fse.pathExists(npm), 'package-lock.json does not exist').toBe(false);
expect(await fse.pathExists(pnpm), 'pnpm-lock.yaml does not exist').toBe(false);

break;
}
case 'pnpm': {
expect(await fse.pathExists(pnpm), 'for pnpm: pnpm-lock.yaml exists').toBe(true);
expect(await fse.pathExists(npm), 'package-lock.json does not exist').toBe(false);
expect(await fse.pathExists(yarn), 'yarn.lock does not exist').toBe(false);

break;
}

default:
throw new Error(`unknown packageManager: ${packageManager}`);
}
});

it('"prepare" built the addon', async () => {
let contents = await dirContents(distDir);

expect(contents).to.deep.equal(['index.js', 'index.js.map']);
});

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

it('builds the addon', async () => {
let { exitCode } = await runScript({ cwd, script: 'build', packageManager });

expect(exitCode).toEqual(0);

let contents = await dirContents(distDir);

expect(contents).to.deep.equal(['index.js', 'index.js.map']);
});

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

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

it('lints all pass', async () => {
let { exitCode } = await runScript({ cwd, script: 'lint', packageManager });

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

0 comments on commit be0bbe3

Please sign in to comment.