From 7930a2181d3530ac37f09d7b92beda9fff2d44f3 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:34:05 -0300 Subject: [PATCH 1/6] ci(tdd): include a failure case --- fixtures/each-api/after-failure.test.ts | 65 +++++++++++++++++++++++++ fixtures/each-api/async.test.ts | 13 +++-- test/e2e/each-api/failure.test.ts | 27 ++++++++++ test/e2e/each-api/order.test.ts | 1 + 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 fixtures/each-api/after-failure.test.ts create mode 100644 test/e2e/each-api/failure.test.ts diff --git a/fixtures/each-api/after-failure.test.ts b/fixtures/each-api/after-failure.test.ts new file mode 100644 index 00000000..96fdf8a3 --- /dev/null +++ b/fixtures/each-api/after-failure.test.ts @@ -0,0 +1,65 @@ +import { readFile, writeFile, rm, mkdir } from 'node:fs/promises'; +import { + beforeEach, + afterEach, + log, + test, + describe, + assert, +} from '../../src/modules/index.js'; + +const testDir = '../../.temp'; +const testFile = `${testDir}/each-hook`; + +const clearFixture = async () => { + await rm(testFile); + await rm(testDir, { recursive: true, force: true }); + log(' - Cleaning'); +}; + +const writeFixture = async () => { + await mkdir(testDir); + await writeFile(testFile, 'test', 'utf-8'); + log(' - Writing'); +}; + +const toTest = async (message: string) => { + await readFile(testFile, 'utf-8'); + return message; +}; + +beforeEach(async () => { + log('- before beforeEach writeFixture'); + + await writeFixture(); + + log('- after beforeEach writeFixture'); +}); + +afterEach(async () => { + log('- before afterEach clearFixture'); + + await clearFixture(); + + log('- after afterEach clearFixture'); +}); + +describe(async () => { + await writeFixture(); + + await test('first test', async () => { + log(' before first test'); + + assert(true, await toTest('first test')); + + log(' after first test'); + }); + + await test('second test', async () => { + log(' before second test'); + + assert(true, await toTest('second test')); + + log(' after second test'); + }); +}); diff --git a/fixtures/each-api/async.test.ts b/fixtures/each-api/async.test.ts index 7fed6500..c4842e5d 100644 --- a/fixtures/each-api/async.test.ts +++ b/fixtures/each-api/async.test.ts @@ -1,3 +1,4 @@ +import { readFile, writeFile, rm, mkdir } from 'node:fs/promises'; import { beforeEach, afterEach, @@ -5,21 +6,25 @@ import { test, describe, assert, - sleep, } from '../../src/modules/index.js'; +const testDir = '../../.temp'; +const testFile = `${testDir}/each-hook`; + const clearFixture = async () => { - await sleep(250); + await rm(testFile); + await rm(testDir, { recursive: true, force: true }); log(' - Cleaning'); }; const writeFixture = async () => { - await sleep(250); + await mkdir(testDir); + await writeFile(testFile, 'test', 'utf-8'); log(' - Writing'); }; const toTest = async (message: string) => { - await sleep(500); + await readFile(testFile, 'utf-8'); return message; }; diff --git a/test/e2e/each-api/failure.test.ts b/test/e2e/each-api/failure.test.ts new file mode 100644 index 00000000..612e1b59 --- /dev/null +++ b/test/e2e/each-api/failure.test.ts @@ -0,0 +1,27 @@ +import { describe } from '../../../src/modules/helpers/describe.js'; +import { it } from '../../../src/modules/helpers/it.js'; +import { assert } from '../../../src/modules/essentials/assert.js'; +import { inspectCLI, isProduction } from '../../helpers/capture-cli.test.js'; +import { skip } from '../../../src/modules/helpers/skip.js'; + +if (isProduction) { + skip(); +} + +describe('Testing afterEach execution after a test failure', async () => { + await it(async () => { + const results = await inspectCLI( + 'npx tsx ../../src/bin/index.ts after-failure.test.ts -d', + { + cwd: 'fixtures/each-api', + } + ); + + if (results.exitCode !== 0) { + console.log(results.stdout); + console.log(results.stderr); + } + + assert.strictEqual(results.exitCode, 0, 'Exit Code needs to be 0'); + }); +}); diff --git a/test/e2e/each-api/order.test.ts b/test/e2e/each-api/order.test.ts index b2066d85..a91924bf 100644 --- a/test/e2e/each-api/order.test.ts +++ b/test/e2e/each-api/order.test.ts @@ -43,6 +43,7 @@ describe('Testing ', async () => { const actual = results.stdout.split('\n'); if (results.exitCode !== 0) { + console.log(results.stdout); console.log(results.stderr); } From b33d5c047d268df93f5d38b5804c7c73cc5ee451 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:16:54 -0300 Subject: [PATCH 2/6] ci: fix test failure case --- fixtures/each-api/async.test.ts | 13 ++++--------- test/e2e/each-api/failure.test.ts | 6 ++---- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/fixtures/each-api/async.test.ts b/fixtures/each-api/async.test.ts index c4842e5d..7fed6500 100644 --- a/fixtures/each-api/async.test.ts +++ b/fixtures/each-api/async.test.ts @@ -1,4 +1,3 @@ -import { readFile, writeFile, rm, mkdir } from 'node:fs/promises'; import { beforeEach, afterEach, @@ -6,25 +5,21 @@ import { test, describe, assert, + sleep, } from '../../src/modules/index.js'; -const testDir = '../../.temp'; -const testFile = `${testDir}/each-hook`; - const clearFixture = async () => { - await rm(testFile); - await rm(testDir, { recursive: true, force: true }); + await sleep(250); log(' - Cleaning'); }; const writeFixture = async () => { - await mkdir(testDir); - await writeFile(testFile, 'test', 'utf-8'); + await sleep(250); log(' - Writing'); }; const toTest = async (message: string) => { - await readFile(testFile, 'utf-8'); + await sleep(500); return message; }; diff --git a/test/e2e/each-api/failure.test.ts b/test/e2e/each-api/failure.test.ts index 612e1b59..d608b669 100644 --- a/test/e2e/each-api/failure.test.ts +++ b/test/e2e/each-api/failure.test.ts @@ -17,10 +17,8 @@ describe('Testing afterEach execution after a test failure', async () => { } ); - if (results.exitCode !== 0) { - console.log(results.stdout); - console.log(results.stderr); - } + console.log(results.stdout); + console.log(results.stderr); assert.strictEqual(results.exitCode, 0, 'Exit Code needs to be 0'); }); From bcb6cafdcc362c0c5bbc21facd3ae1de5d0323e9 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:40:18 -0300 Subject: [PATCH 3/6] chore: unify `it` and `test` --- fixtures/each-api/after-failure.test.ts | 19 ++--- src/configs/indentation.ts | 1 - src/modules/helpers/it.ts | 94 ++++++++++++++----------- src/modules/helpers/test.ts | 78 +------------------- src/services/assert.ts | 11 ++- test/e2e/each-api/failure.test.ts | 7 +- 6 files changed, 74 insertions(+), 136 deletions(-) diff --git a/fixtures/each-api/after-failure.test.ts b/fixtures/each-api/after-failure.test.ts index 96fdf8a3..c8ab488b 100644 --- a/fixtures/each-api/after-failure.test.ts +++ b/fixtures/each-api/after-failure.test.ts @@ -12,9 +12,11 @@ const testDir = '../../.temp'; const testFile = `${testDir}/each-hook`; const clearFixture = async () => { - await rm(testFile); - await rm(testDir, { recursive: true, force: true }); - log(' - Cleaning'); + try { + await rm(testFile); + await rm(testDir, { recursive: true, force: true }); + log(' - Cleaning'); + } catch {} }; const writeFixture = async () => { @@ -45,7 +47,7 @@ afterEach(async () => { }); describe(async () => { - await writeFixture(); + await clearFixture(); await test('first test', async () => { log(' before first test'); @@ -55,11 +57,12 @@ describe(async () => { log(' after first test'); }); - await test('second test', async () => { - log(' before second test'); + await writeFixture(); + await test('Force failure', async () => { + log(' before first test'); - assert(true, await toTest('second test')); + assert(true, await toTest('first test')); - log(' after second test'); + log(' after first test'); }); }); diff --git a/src/configs/indentation.ts b/src/configs/indentation.ts index 65e1c83f..258ca2f5 100644 --- a/src/configs/indentation.ts +++ b/src/configs/indentation.ts @@ -2,6 +2,5 @@ export const indentation = { test: ' ', stdio: ' ', hasDescribe: false, - hasTest: false, hasIt: false, }; diff --git a/src/modules/helpers/it.ts b/src/modules/helpers/it.ts index 5a8fd0ee..d533c5c2 100644 --- a/src/modules/helpers/it.ts +++ b/src/modules/helpers/it.ts @@ -19,61 +19,75 @@ export async function it( (() => unknown | Promise)?, ] ): Promise { - let message: string | undefined; - let cb: () => unknown | Promise; + try { + let message: string | undefined; + let cb: () => unknown | Promise; - const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0; - const FILE = env.FILE; + const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0; + const FILE = env.FILE; - if (typeof args[0] === 'string') { - message = args[0]; - cb = args[1] as () => unknown | Promise; - } else { - cb = args[0] as () => unknown | Promise; - } + if (typeof args[0] === 'string') { + message = args[0]; + cb = args[1] as () => unknown | Promise; + } else { + cb = args[0] as () => unknown | Promise; + } - if (message) { - indentation.hasIt = true; + if (message) { + indentation.hasIt = true; - Write.log( - isPoku && !indentation.hasDescribe - ? /* c8 ignore next 2 */ - `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim()}` - : `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}` - ); - } + Write.log( + isPoku && !indentation.hasDescribe + ? /* c8 ignore next 2 */ + `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim()}` + : `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}` + ); + } - if (typeof each.before.cb === 'function') { - const beforeResult = each.before.cb(); + if (typeof each.before.cb === 'function') { + const beforeResult = each.before.cb(); - if (beforeResult instanceof Promise) { - await beforeResult; + if (beforeResult instanceof Promise) { + await beforeResult; + } } - } - const start = hrtime(); - const resultCb = cb(); + const start = hrtime(); + const resultCb = cb(); - if (resultCb instanceof Promise) { - await resultCb; - } + if (resultCb instanceof Promise) { + await resultCb; + } - const end = hrtime(start); + const end = hrtime(start); - if (typeof each.after.cb === 'function') { - const afterResult = each.after.cb(); + if (typeof each.after.cb === 'function') { + const afterResult = each.after.cb(); - if (afterResult instanceof Promise) { - await afterResult; + if (afterResult instanceof Promise) { + await afterResult; + } } - } - if (message) { - const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); + if (message) { + const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); + indentation.hasIt = false; + Write.log( + `${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).success().bold()} ${format(`› ${total}ms`).success().dim()}` + ); + } + } catch (error) { indentation.hasIt = false; - Write.log( - `${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).success().bold()} ${format(`› ${total}ms`).success().dim()}` - ); + + if (typeof each.after.cb === 'function') { + const afterResult = each.after.cb(); + + if (afterResult instanceof Promise) { + await afterResult; + } + } + + throw error; } } diff --git a/src/modules/helpers/test.ts b/src/modules/helpers/test.ts index a6c1e8a8..a5e1bfa2 100644 --- a/src/modules/helpers/test.ts +++ b/src/modules/helpers/test.ts @@ -1,79 +1,5 @@ /* c8 ignore next */ // ? -import { hrtime, env } from 'node:process'; -import { each } from '../../configs/each.js'; -import { indentation } from '../../configs/indentation.js'; -import { format } from '../../services/format.js'; -import { Write } from '../../services/write.js'; +import { it } from './it.js'; -export async function test( - message: string, - cb: () => Promise -): Promise; -export function test(message: string, cb: () => unknown): void; -export async function test(cb: () => Promise): Promise; -export function test(cb: () => unknown): void; /* c8 ignore next */ // ? -export async function test( - ...args: [ - string | (() => unknown | Promise), - (() => unknown | Promise)?, - ] -): Promise { - let message: string | undefined; - let cb: () => unknown | Promise; - - const isPoku = typeof env?.FILE === 'string' && env?.FILE.length > 0; - const FILE = env.FILE; - - if (typeof args[0] === 'string') { - message = args[0]; - cb = args[1] as () => unknown | Promise; - } else { - cb = args[0] as () => unknown | Promise; - } - - if (message) { - indentation.hasTest = true; - - Write.log( - isPoku - ? /* c8 ignore next 2 */ - format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim() - : format(`◌ ${message}`).dim() - ); - } - - if (typeof each.before.cb === 'function') { - const beforeResult = each.before.cb(); - - if (beforeResult instanceof Promise) { - await beforeResult; - } - } - - const start = hrtime(); - const resultCb = cb(); - - if (resultCb instanceof Promise) { - await resultCb; - } - - const end = hrtime(start); - - if (typeof each.after.cb === 'function') { - const afterResult = each.after.cb(); - - if (afterResult instanceof Promise) { - await afterResult; - } - } - - if (message) { - const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); - - indentation.hasTest = false; - Write.log( - `${format(`● ${message}`).success().bold()} ${format(`› ${total}ms`).success().dim()}` - ); - } -} +export const test = it; diff --git a/src/services/assert.ts b/src/services/assert.ts index 9a57cfa5..ec185325 100644 --- a/src/services/assert.ts +++ b/src/services/assert.ts @@ -23,7 +23,7 @@ export const processAssert = async ( const FILE = env.FILE; let preIdentation = ''; - if (indentation.hasDescribe || indentation.hasTest) { + if (indentation.hasDescribe) { preIdentation += ' '; } @@ -40,12 +40,9 @@ export const processAssert = async ( if (typeof options.message === 'string') { const message = - isPoku && - !indentation.hasDescribe && - !indentation.hasIt && - /* c8 ignore next 2 */ - !indentation.hasTest - ? `${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}` + isPoku && !indentation.hasDescribe && !indentation.hasIt + ? /* c8 ignore next 2 */ + `${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}` : `${preIdentation}${format(`✔ ${options.message}`).success().bold()}`; Write.log(message); diff --git a/test/e2e/each-api/failure.test.ts b/test/e2e/each-api/failure.test.ts index d608b669..02bead6d 100644 --- a/test/e2e/each-api/failure.test.ts +++ b/test/e2e/each-api/failure.test.ts @@ -3,6 +3,7 @@ import { it } from '../../../src/modules/helpers/it.js'; import { assert } from '../../../src/modules/essentials/assert.js'; import { inspectCLI, isProduction } from '../../helpers/capture-cli.test.js'; import { skip } from '../../../src/modules/helpers/skip.js'; +import { statSync } from 'node:fs'; if (isProduction) { skip(); @@ -17,9 +18,7 @@ describe('Testing afterEach execution after a test failure', async () => { } ); - console.log(results.stdout); - console.log(results.stderr); - - assert.strictEqual(results.exitCode, 0, 'Exit Code needs to be 0'); + assert.strictEqual(results.exitCode, 1, 'Exit Code needs to be 1'); + assert.throws(() => statSync('./.temp')); }); }); From c1f86f6be81835781316a48e5c369bfca2e0c519 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 25 Jul 2024 04:49:40 -0300 Subject: [PATCH 4/6] ci: improve tests --- .gitignore | 1 + fixtures/each-api/after-failure.test.ts | 2 +- fixtures/no-runner/basic-logs.test.ts | 54 +++++++++++++++++++ src/modules/helpers/describe.ts | 1 - src/modules/helpers/it.ts | 3 +- src/services/assert.ts | 4 +- test/c8.test.ts | 14 +++++ test/e2e/basic-logs.test.ts | 41 ++++++++++++++ test/e2e/each-api/failure.test.ts | 2 +- .../before-and-after-each/invalid.test.ts | 31 +++++++++++ test/integration/it/it.test.ts | 3 ++ 11 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 fixtures/no-runner/basic-logs.test.ts create mode 100644 test/e2e/basic-logs.test.ts create mode 100644 test/integration/before-and-after-each/invalid.test.ts diff --git a/.gitignore b/.gitignore index 35044a06..8ac24017 100755 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ node_modules .env .nyc_output /.temp +/.temp2 /test-src /test-tests /test-before-and-after-each.json diff --git a/fixtures/each-api/after-failure.test.ts b/fixtures/each-api/after-failure.test.ts index c8ab488b..d701ce1d 100644 --- a/fixtures/each-api/after-failure.test.ts +++ b/fixtures/each-api/after-failure.test.ts @@ -8,7 +8,7 @@ import { assert, } from '../../src/modules/index.js'; -const testDir = '../../.temp'; +const testDir = '../../.temp2'; const testFile = `${testDir}/each-hook`; const clearFixture = async () => { diff --git a/fixtures/no-runner/basic-logs.test.ts b/fixtures/no-runner/basic-logs.test.ts new file mode 100644 index 00000000..065004c0 --- /dev/null +++ b/fixtures/no-runner/basic-logs.test.ts @@ -0,0 +1,54 @@ +import { assert } from '../../src/modules/essentials/assert.js'; +import { test } from '../../src/modules/helpers/test.js'; +import { describe } from '../../src/modules/helpers/describe.js'; +import { it } from '../../src/modules/helpers/it.js'; + +assert(true, 'Should emit a basic assetion log'); + +test('Should emit a basic test scope log', () => { + // ... +}); + +describe('Should emit a basic test scope log', () => { + // ... +}); + +it('Should emit a basic it scope log', () => { + // ... +}); + +test('Should emit a basic test scope log', () => { + assert(true, 'Should emit a basic assetion log'); +}); + +describe('Should emit a basic test scope log', () => { + assert(true, 'Should emit a basic assetion log'); +}); + +it('Should emit a basic test scope log', () => { + assert(true, 'Should emit a basic assetion log'); +}); + +describe('Should emit a basic test scope log', () => { + it('Should emit a basic it scope log', () => { + // ... + }); +}); + +describe('Should emit a basic test scope log', () => { + test('Should emit a basic test scope log', () => { + // ... + }); +}); + +describe('Should emit a basic test scope log', () => { + it('Should emit a basic it scope log', () => { + assert(true, 'Should emit a basic assetion log'); + }); +}); + +describe('Should emit a basic test scope log', () => { + test('Should emit a basic test scope log', () => { + assert(true, 'Should emit a basic assetion log'); + }); +}); diff --git a/src/modules/helpers/describe.ts b/src/modules/helpers/describe.ts index e345874c..b42015cc 100644 --- a/src/modules/helpers/describe.ts +++ b/src/modules/helpers/describe.ts @@ -43,7 +43,6 @@ export async function describe( indentation.hasDescribe = true; const { background, icon } = options || {}; - /* c8 ignore next */ const message = `${cb ? format('◌').dim() : icon || '☰'} ${cb ? format(isPoku ? `${title} › ${format(`${FILE}`).italic().gray()}` : title).dim() : format(title).bold() || ''}`; const noBackground = !background; diff --git a/src/modules/helpers/it.ts b/src/modules/helpers/it.ts index d533c5c2..daddac46 100644 --- a/src/modules/helpers/it.ts +++ b/src/modules/helpers/it.ts @@ -38,8 +38,7 @@ export async function it( Write.log( isPoku && !indentation.hasDescribe - ? /* c8 ignore next 2 */ - `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim()}` + ? `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message} › ${format(`${FILE}`).italic().gray()}`).dim()}` : `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}` ); } diff --git a/src/services/assert.ts b/src/services/assert.ts index ec185325..4d9b8d27 100644 --- a/src/services/assert.ts +++ b/src/services/assert.ts @@ -41,8 +41,7 @@ export const processAssert = async ( if (typeof options.message === 'string') { const message = isPoku && !indentation.hasDescribe && !indentation.hasIt - ? /* c8 ignore next 2 */ - `${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}` + ? `${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}` : `${preIdentation}${format(`✔ ${options.message}`).success().bold()}`; Write.log(message); @@ -112,7 +111,6 @@ export const processAssert = async ( // Non-assertion errors throw error; } - /* c8 ignore stop */ }; /* c8 ignore next */ // ? diff --git a/test/c8.test.ts b/test/c8.test.ts index facd7e90..75122097 100644 --- a/test/c8.test.ts +++ b/test/c8.test.ts @@ -2,8 +2,22 @@ import { env } from 'node:process'; import { poku, test, describe, it, assert } from '../src/modules/index.js'; import { isWindows } from '../src/parsers/get-runner.js'; import { inspectCLI } from './helpers/capture-cli.test.js'; +import { rmSync } from 'node:fs'; test(async () => { + const toRemove = [ + '/.temp', + '/test-src', + '/test-tests', + '/test-before-and-after-each.json', + ]; + + for (const path of toRemove) { + try { + rmSync(path, { force: true, recursive: true }); + } catch {} + } + await describe('CLI', async () => { await it('Sequential (Just Touch)', async () => { const results = await inspectCLI( diff --git a/test/e2e/basic-logs.test.ts b/test/e2e/basic-logs.test.ts new file mode 100644 index 00000000..e788d74e --- /dev/null +++ b/test/e2e/basic-logs.test.ts @@ -0,0 +1,41 @@ +import { describe } from '../../src/modules/helpers/describe.js'; +import { it } from '../../src/modules/helpers/it.js'; +import { assert } from '../../src/modules/essentials/assert.js'; +import { inspectCLI, isProduction } from '../helpers/capture-cli.test.js'; +import { skip } from '../../src/modules/helpers/skip.js'; + +if (isProduction) { + skip(); +} + +// const offset = 33; + +describe('Basic logs with Runner', async () => { + await it('Basic Logs without using Poku Runner', async () => { + const results = await inspectCLI( + 'npx tsx ./fixtures/no-runner/basic-logs.test.ts' + ); + + console.log(results.stdout); + console.log(results.stderr); + + assert.strictEqual(results.exitCode, 0, 'Exit Code needs to be 0'); + }); + + await it('Basic Logs without using Poku Runner + ENV', async () => { + const results = await inspectCLI( + 'npx tsx ./fixtures/no-runner/basic-logs.test.ts', + { + env: { + ...process.env, + FILE: 'path-file', + }, + } + ); + + console.log(results.stdout); + console.log(results.stderr); + + assert.strictEqual(results.exitCode, 0, 'Exit Code needs to be 0'); + }); +}); diff --git a/test/e2e/each-api/failure.test.ts b/test/e2e/each-api/failure.test.ts index 02bead6d..07a87da8 100644 --- a/test/e2e/each-api/failure.test.ts +++ b/test/e2e/each-api/failure.test.ts @@ -19,6 +19,6 @@ describe('Testing afterEach execution after a test failure', async () => { ); assert.strictEqual(results.exitCode, 1, 'Exit Code needs to be 1'); - assert.throws(() => statSync('./.temp')); + assert.throws(() => statSync('./.temp2')); }); }); diff --git a/test/integration/before-and-after-each/invalid.test.ts b/test/integration/before-and-after-each/invalid.test.ts new file mode 100644 index 00000000..0c30eefd --- /dev/null +++ b/test/integration/before-and-after-each/invalid.test.ts @@ -0,0 +1,31 @@ +import { nodeVersion, getRuntime } from '../../../src/parsers/get-runtime.js'; +import { skip } from '../../../src/modules/helpers/skip.js'; + +if (nodeVersion && nodeVersion < 16) { + skip(); +} + +import { test } from '../../../src/modules/helpers/test.js'; +import { poku } from '../../../src/modules/essentials/poku.js'; +import { assert } from '../../../src/modules/essentials/assert.js'; + +const runtime = getRuntime(); + +if (runtime === 'deno') { + skip(); +} + +test('Before and After Each: updating an external file', async () => { + const prepareService = true; + const resetService = true; + + // @ts-expect-error + const exitCode = await poku('./test/integration/import.test.ts', { + noExit: true, + quiet: true, + beforeEach: prepareService, + afterEach: resetService, + }); + + assert.strictEqual(exitCode, 0, 'Should ignore if hooks are invalid'); +}); diff --git a/test/integration/it/it.test.ts b/test/integration/it/it.test.ts index 0aa501c2..1f0d025d 100644 --- a/test/integration/it/it.test.ts +++ b/test/integration/it/it.test.ts @@ -31,3 +31,6 @@ test('Testing "it" method', () => { it('it without describe', async () => await new Promise((resolve) => resolve(undefined))); }); + +it('it without scope', async () => + await new Promise((resolve) => resolve(undefined))); From a6dfec74ecc637e6584471ebe5ffac731c1f350f Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 25 Jul 2024 04:55:33 -0300 Subject: [PATCH 5/6] ci: fix tests --- test/integration/before-and-after-each/invalid.test.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/integration/before-and-after-each/invalid.test.ts b/test/integration/before-and-after-each/invalid.test.ts index 0c30eefd..b46a94cd 100644 --- a/test/integration/before-and-after-each/invalid.test.ts +++ b/test/integration/before-and-after-each/invalid.test.ts @@ -1,17 +1,11 @@ -import { nodeVersion, getRuntime } from '../../../src/parsers/get-runtime.js'; +import { isProduction } from '../../helpers/capture-cli.test.js'; import { skip } from '../../../src/modules/helpers/skip.js'; -if (nodeVersion && nodeVersion < 16) { - skip(); -} - import { test } from '../../../src/modules/helpers/test.js'; import { poku } from '../../../src/modules/essentials/poku.js'; import { assert } from '../../../src/modules/essentials/assert.js'; -const runtime = getRuntime(); - -if (runtime === 'deno') { +if (isProduction) { skip(); } From deab683da54edbb612edc9ca37afd7344bbf906e Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 25 Jul 2024 05:03:13 -0300 Subject: [PATCH 6/6] chore: better name `hasIt` to `hasItOrTest` --- src/configs/indentation.ts | 2 +- src/modules/helpers/it.ts | 6 +++--- src/services/assert.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/configs/indentation.ts b/src/configs/indentation.ts index 258ca2f5..78bbd4f2 100644 --- a/src/configs/indentation.ts +++ b/src/configs/indentation.ts @@ -2,5 +2,5 @@ export const indentation = { test: ' ', stdio: ' ', hasDescribe: false, - hasIt: false, + hasItOrTest: false, }; diff --git a/src/modules/helpers/it.ts b/src/modules/helpers/it.ts index daddac46..7b96eb9d 100644 --- a/src/modules/helpers/it.ts +++ b/src/modules/helpers/it.ts @@ -34,7 +34,7 @@ export async function it( } if (message) { - indentation.hasIt = true; + indentation.hasItOrTest = true; Write.log( isPoku && !indentation.hasDescribe @@ -71,13 +71,13 @@ export async function it( if (message) { const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6); - indentation.hasIt = false; + indentation.hasItOrTest = false; Write.log( `${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).success().bold()} ${format(`› ${total}ms`).success().dim()}` ); } } catch (error) { - indentation.hasIt = false; + indentation.hasItOrTest = false; if (typeof each.after.cb === 'function') { const afterResult = each.after.cb(); diff --git a/src/services/assert.ts b/src/services/assert.ts index 4d9b8d27..a59833ce 100644 --- a/src/services/assert.ts +++ b/src/services/assert.ts @@ -27,7 +27,7 @@ export const processAssert = async ( preIdentation += ' '; } - if (indentation.hasIt) { + if (indentation.hasItOrTest) { preIdentation += ' '; } @@ -40,7 +40,7 @@ export const processAssert = async ( if (typeof options.message === 'string') { const message = - isPoku && !indentation.hasDescribe && !indentation.hasIt + isPoku && !indentation.hasDescribe && !indentation.hasItOrTest ? `${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}` : `${preIdentation}${format(`✔ ${options.message}`).success().bold()}`;