Skip to content

Commit

Permalink
ci: improve tests (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored Jun 17, 2024
1 parent 9ab7202 commit d9b6330
Show file tree
Hide file tree
Showing 23 changed files with 1,379 additions and 1,494 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Enjoying **Poku**? Give him a star to show your support 🌟

<img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easier and Less Verbose<br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> [**Node.js**][node-version-url] familiar **API**<br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Instantly re-run related tests in `watch` mode<br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Run **CJS** (**CommonJS**) files directly with [**Deno**][deno-version-url]<br />
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><img width="16" height="16" alt="check" src="https://raw.githubusercontent.com/wellwelwel/poku/main/.github/assets/readme/check.svg"> Easily handle, **servers**, **services**, **processes**, and **ports**<br />

Expand Down Expand Up @@ -174,8 +175,8 @@ deno run npm:poku

- [**test**](https://poku.io/docs/documentation/helpers/test)
, [**describe**](https://poku.io/docs/documentation/helpers/describe) and [**it**](https://poku.io/docs/documentation/helpers/it) _(organize, group, and isolate tests)_
- [**watch**](https://poku.io/docs/documentation/poku/options/watch) _(watch for changes and re-run related test files)_
- [**beforeEach**](https://poku.io/docs/category/beforeeach-and-aftereach) and [**afterEach**](https://poku.io/docs/category/beforeeach-and-aftereach) _(hooks for test setup and teardown)_
- [**watch**](https://poku.io/docs/documentation/poku/options/watch) _(watch test files for changes)_
- [**startScript**](https://poku.io/docs/documentation/startScript) _(run **package.json** scripts in background)_
- [**startService**](https://poku.io/docs/documentation/startService) _(run files in background)_
- [**kill**](https://poku.io/docs/documentation/processes/kill) _(terminate ports, port ranges, and PIDs)_
Expand Down
184 changes: 92 additions & 92 deletions test/e2e/background-process.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe } from '../../src/modules/describe.js';
import { test } from '../../src/modules/test.js';
import { it } from '../../src/modules/it.js';
import { assert } from '../../src/modules/assert.js';
import { startScript, startService } from '../../src/modules/create-service.js';
import { legacyFetch } from '../helpers/legacy-fetch.test.js';
Expand All @@ -9,102 +9,55 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
(async () => {
const runtime = getRuntime();

await test(async () => {
describe('Start Service (Single Port)', { icon: '🔀' });

const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction ? 'fixtures/server' : 'ci/fixtures/server',
});

const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku service is online'
);
await describe('Start Service (Single Port)', async () => {
await it(async () => {
const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
});

await server.end(4000);
});
const res = await legacyFetch('localhost', 4000);

await test(async () => {
describe('Start Script (Single Port)', { icon: '🔀' });
assert.strictEqual(res?.statusCode, 200, 'Service is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku service is online'
);

const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction ? 'fixtures/server' : 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
await server.end(4000);
});

const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku script is online'
);

await server.end(4001);
});

await test(async () => {
describe('Start Service (Multiple Ports)', {
icon: '🔀',
});

const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction ? 'fixtures/server' : 'ci/fixtures/server',
});

const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku service is online'
);
await describe('Start Script (Single Port)', async () => {
await it(async () => {
const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
});

await server.end([4000]);
});
const res = await legacyFetch('localhost', 4001);

await test(async () => {
describe('Start Script (Multiple Ports)', {
icon: '🔀',
});
assert.strictEqual(res?.statusCode, 200, 'Script is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku script is online'
);

const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction ? 'fixtures/server' : 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
await server.end(4001);
});

const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku script is online'
);

await server.end([4001]);
});

if (runtime === 'node') {
await test(async () => {
describe('Start Service (No Ports)', {
icon: '🔀',
});

await describe('Start Service (Multiple Ports)', async () => {
await it(async () => {
const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
cwd:
Expand All @@ -122,14 +75,12 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
'Poku service is online'
);

await server.end();
await server.end([4000]);
});
});

await test(async () => {
describe('Start Script (No Ports)', {
icon: '🔀',
});

await describe('Start Script (Multiple Ports)', async () => {
await it(async () => {
const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
cwd:
Expand All @@ -148,7 +99,56 @@ import { getRuntime } from '../../src/helpers/get-runtime.js';
'Poku script is online'
);

await server.end();
await server.end([4001]);
});
});

if (runtime === 'node') {
await describe('Start Service (No Ports)', async () => {
await it(async () => {
const server = await startService(`server-a.${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
});

const res = await legacyFetch('localhost', 4000);

assert.strictEqual(res?.statusCode, 200, 'Service is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku service is online'
);

await server.end();
});
});

await describe('Start Script (No Ports)', async () => {
await it(async () => {
const server = await startScript(`start:${ext}`, {
startAfter: 'ready',
cwd:
ext === 'ts' || isProduction
? 'fixtures/server'
: 'ci/fixtures/server',
runner: runtime === 'node' ? 'npm' : runtime,
});

const res = await legacyFetch('localhost', 4001);

assert.strictEqual(res?.statusCode, 200, 'Script is on');
assert.deepStrictEqual(
JSON.parse(res?.body),
{ name: 'Poku' },
'Poku script is online'
);

await server.end();
});
});
}
})();
5 changes: 1 addition & 4 deletions test/e2e/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { describe } from '../../src/modules/describe.js';
import { test } from '../../src/modules/test.js';
import { assert } from '../../src/modules/assert.js';
import { executeCLI, ext, isProduction } from '../helpers/capture-cli.test.js';
Expand All @@ -8,9 +7,7 @@ const runtime = getRuntime();

if (runtime === 'deno' && !isProduction) process.exit(0);

test(async () => {
describe('Poku Test Runner: CLI', { icon: '🐷' });

test('Poku Test Runner: CLI', async () => {
const output = await executeCLI([
ext === 'ts' || isProduction
? `src/bin/index.${ext}`
Expand Down
Loading

0 comments on commit d9b6330

Please sign in to comment.