Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterize the default tests for quickly adding scenarios to test #94

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 102 additions & 86 deletions tests/default.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,93 @@ import { existsSync, writeFileSync } from 'fs';
import stripAnsi from 'strip-ansi';
import { newProjectWithFixtures } from './helpers.mjs';

const SCENARIOS = [
{
flags: [
/* none, default */
],
fixturePath: join(import.meta.dirname, 'fixture'),
},
];

describe('basic functionality', function () {
let project = newProjectWithFixtures({
fixturePath: join(__dirname, 'fixture'),
});

it('verify files', async function () {
expect(
!existsSync(join(project.dir(), 'app/index.html')),
'the app index.html has been removed',
);
expect(
existsSync(join(project.dir(), 'index.html')),
'the root index.html has been added',
);
});

it('successfully lints', async function () {
let result = await project.execa('pnpm', ['lint']);

console.log(result.stdout);
});

it('successfully builds', async function () {
let result = await project.execa('pnpm', ['build']);

console.log(result.stdout);
});

it('successfully runs tests', async function () {
let result;

try {
result = await project.execa('pnpm', ['test:ember']);
} catch (err) {
console.log(err.stdout, err.stderr);
throw err;
}

// make sure that each of the tests that we expect actually show up
// alternatively we can change this to search for `pass 3`
expect(result.stdout).to.contain(
'Acceptance | welcome page: visiting /index shows the welcome page',
);
expect(result.stdout).to.contain('Acceptance | styles: visiting /styles');

console.log(result.stdout);
});

it('successfully runs tests in dev mode', async function () {
await project.$`pnpm install --save-dev testem http-proxy`;
let appURL;

let server;

try {
server = project.execa('pnpm', ['start']);

await new Promise((resolve) => {
server.stdout.on('data', (line) => {
let result = /Local:\s+(https?:\/\/.*)\//g.exec(
stripAnsi(line.toString()),
);
for (let { flags, fixturePath } of SCENARIOS) {
describe(`with flags: '${flags.join(' ')}'`, function () {
let project = newProjectWithFixtures({
fixturePath,
flags,
});

it('verify files', async function () {
expect(
!existsSync(join(project.dir(), 'app/index.html')),
'the app index.html has been removed',
);
expect(
existsSync(join(project.dir(), 'index.html')),
'the root index.html has been added',
);
});

it('successfully lints', async function () {
let result = await project.execa('pnpm', ['lint']);

console.log(result.stdout);
});

it('successfully builds', async function () {
let result = await project.execa('pnpm', ['build']);

console.log(result.stdout);
});

if (result) {
appURL = result[1];
resolve();
}
});
it('successfully runs tests', async function () {
let result;

try {
result = await project.execa('pnpm', ['test:ember']);
} catch (err) {
console.log(err.stdout, err.stderr);
throw 'Failed to successfully run test:ember';
}

// make sure that each of the tests that we expect actually show up
// alternatively we can change this to search for `pass 3`
expect(result.stdout).to.contain(
'Acceptance | welcome page: visiting /index shows the welcome page',
);
expect(result.stdout).to.contain(
'Acceptance | styles: visiting /styles',
);

console.log(result.stdout);
});

writeFileSync(
join(project.dir(), 'testem-dev.js'),
`module.exports = {
it('successfully runs tests in dev mode', async function () {
await project.$`pnpm install --save-dev testem http-proxy`;
let appURL;

let server;

try {
server = project.execa('pnpm', ['start']);

await new Promise((resolve) => {
server.stdout.on('data', (line) => {
let result = /Local:\s+(https?:\/\/.*)\//g.exec(
stripAnsi(line.toString()),
);

if (result) {
appURL = result[1];
resolve();
}
});
});

writeFileSync(
join(project.dir(), 'testem-dev.js'),
`module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: ['Chrome'],
Expand All @@ -101,21 +115,23 @@ describe('basic functionality', function () {
],
};
`,
);

let testResult = await project.execa('pnpm', [
'testem',
'--file',
'testem-dev.js',
'ci',
]);
expect(testResult.exitCode).to.eq(0, testResult.output);
} finally {
server?.kill('SIGINT');
}
});

it('successfully optimizes deps', function () {
return project.execa('pnpm', ['vite', 'optimize', '--force']);
});
);

let testResult = await project.execa('pnpm', [
'testem',
'--file',
'testem-dev.js',
'ci',
]);
expect(testResult.exitCode).to.eq(0, testResult.output);
} finally {
server?.kill('SIGINT');
}
});

it('successfully optimizes deps', function () {
return project.execa('pnpm', ['vite', 'optimize', '--force']);
});
});
}
});