Skip to content

Commit f2b3d9c

Browse files
committed
Split test tests
1 parent 31c4029 commit f2b3d9c

1 file changed

Lines changed: 53 additions & 27 deletions

File tree

tests/tests.test.mjs

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import { beforeAll, describe, it, expect } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import fixturify from 'fixturify';
33
import stripAnsi from 'strip-ansi';
44

55
import { generateApp } from './helpers.mjs';
66

77
describe('Slow(JavaScript): Runs tests', async function () {
8-
let app;
9-
10-
beforeAll(async function () {
11-
app = await generateApp({ flags: ['--pnpm'], skipNpm: false });
12-
});
13-
148
it('runs in a freshly generated app', async function () {
9+
let app = await generateApp({ flags: ['--pnpm'], skipNpm: false });
10+
1511
let { stdout: stdout1, exitCode: exitCode1 } = await app.execa('pnpm', [
1612
'test',
1713
]);
@@ -26,6 +22,10 @@ describe('Slow(JavaScript): Runs tests', async function () {
2622
expect(stdout1).to.contain('# todo 0');
2723
expect(stdout1).to.contain('# ok');
2824
expect(exitCode1).to.equal(0);
25+
});
26+
27+
it('runs in an app with fixtures', async function () {
28+
let app = await generateApp({ flags: ['--pnpm'], skipNpm: false });
2929

3030
fixturify.writeSync(
3131
app.dir,
@@ -52,11 +52,14 @@ describe('Slow(JavaScript): Runs tests', async function () {
5252
expect(stdout2).to.contain('# todo 0');
5353
expect(stdout2).to.contain('# ok');
5454
expect(exitCode2).to.equal(0);
55+
});
5556

56-
let fixtures = fixturify.readSync('./tests/fixtures/tests-js-20');
57+
it('runs when serving /tests', async function () {
58+
let app = await generateApp({ flags: ['--pnpm'], skipNpm: false });
5759

5860
await app.execa('pnpm', ['install', '--save-dev', 'testem', 'http-proxy']);
5961

62+
let fixtures = fixturify.readSync('./tests/fixtures/tests-js-20');
6063
let server;
6164

6265
try {
@@ -65,9 +68,12 @@ describe('Slow(JavaScript): Runs tests', async function () {
6568
let appURL = await new Promise((resolve) => {
6669
// Read app url from Vite server output
6770
server.stdout.on('data', (line) => {
68-
let result = /Local:\s+(https?:\/\/.*)\//g.exec(
69-
stripAnsi(line.toString()),
70-
);
71+
let parsed = stripAnsi(line.toString());
72+
let result = /Local:\s+(https?:\/\/.*)\//g.exec(parsed);
73+
74+
if (process.env.CI) {
75+
console.log(parsed);
76+
}
7177

7278
if (result) {
7379
resolve(result[1]);
@@ -88,25 +94,25 @@ describe('Slow(JavaScript): Runs tests', async function () {
8894
'ci',
8995
]);
9096

91-
expect(testResult.exitCode).to.eq(0, testResult.output);
97+
if (process.env.CI) {
98+
console.log(testResult.stdout);
99+
console.log(testResult.stderr);
100+
}
101+
102+
expect(testResult.exitCode).to.eq(0);
92103
} finally {
93-
server?.kill('SIGINT');
94-
await server;
104+
server?.kill('SIGKILL');
95105
}
96106
});
97107
});
98108

99109
describe('Slow(TypeScript): Runs tests', async function () {
100-
let app;
101-
102-
beforeAll(async function () {
103-
app = await generateApp({
110+
it('runs in a freshly generated app', async function () {
111+
let app = await generateApp({
104112
flags: ['--pnpm', '--typescript'],
105113
skipNpm: false,
106114
});
107-
});
108115

109-
it('runs in a freshly generated app', async function () {
110116
let { stdout: stdout1, exitCode: exitCode1 } = await app.execa('pnpm', [
111117
'test',
112118
]);
@@ -121,6 +127,13 @@ describe('Slow(TypeScript): Runs tests', async function () {
121127
expect(stdout1).to.contain('# todo 0');
122128
expect(stdout1).to.contain('# ok');
123129
expect(exitCode1).to.equal(0);
130+
});
131+
132+
it('runs in an app with fixtures', async function () {
133+
let app = await generateApp({
134+
flags: ['--pnpm', '--typescript'],
135+
skipNpm: false,
136+
});
124137

125138
fixturify.writeSync(
126139
app.dir,
@@ -147,11 +160,17 @@ describe('Slow(TypeScript): Runs tests', async function () {
147160
expect(stdout2).to.contain('# todo 0');
148161
expect(stdout2).to.contain('# ok');
149162
expect(exitCode2).to.equal(0);
163+
});
150164

151-
let fixtures = fixturify.readSync('./tests/fixtures/tests-js-20');
165+
it('runs when serving /tests', async function () {
166+
let app = await generateApp({
167+
flags: ['--pnpm', '--typescript'],
168+
skipNpm: false,
169+
});
152170

153171
await app.execa('pnpm', ['install', '--save-dev', 'testem', 'http-proxy']);
154172

173+
let fixtures = fixturify.readSync('./tests/fixtures/tests-js-20');
155174
let server;
156175

157176
try {
@@ -160,9 +179,12 @@ describe('Slow(TypeScript): Runs tests', async function () {
160179
let appURL = await new Promise((resolve) => {
161180
// Read app url from Vite server output
162181
server.stdout.on('data', (line) => {
163-
let result = /Local:\s+(https?:\/\/.*)\//g.exec(
164-
stripAnsi(line.toString()),
165-
);
182+
let parsed = stripAnsi(line.toString());
183+
let result = /Local:\s+(https?:\/\/.*)\//g.exec(parsed);
184+
185+
if (process.env.CI) {
186+
console.log(parsed);
187+
}
166188

167189
if (result) {
168190
resolve(result[1]);
@@ -183,10 +205,14 @@ describe('Slow(TypeScript): Runs tests', async function () {
183205
'ci',
184206
]);
185207

186-
expect(testResult.exitCode).to.eq(0, testResult.output);
208+
if (process.env.CI) {
209+
console.log(testResult.stdout);
210+
console.log(testResult.stderr);
211+
}
212+
213+
expect(testResult.exitCode).to.eq(0);
187214
} finally {
188-
server?.kill('SIGINT');
189-
await server;
215+
server?.kill('SIGKILL');
190216
}
191217
});
192218
});

0 commit comments

Comments
 (0)