From 9c4fcc06336104279036b6fba2840ca8545627e3 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 4 Jul 2023 12:10:12 +0530 Subject: [PATCH] chore: upgrade japa to v3 --- bin/japa_types.ts | 7 ------- bin/test.ts | 24 ++++-------------------- package.json | 8 +++----- tests/cookies/serializer.spec.ts | 5 +++-- 4 files changed, 10 insertions(+), 34 deletions(-) delete mode 100644 bin/japa_types.ts diff --git a/bin/japa_types.ts b/bin/japa_types.ts deleted file mode 100644 index 4ed2308..0000000 --- a/bin/japa_types.ts +++ /dev/null @@ -1,7 +0,0 @@ -import '@japa/runner' - -declare module '@japa/runner' { - interface TestContext { - sleep(time: number): Promise - } -} diff --git a/bin/test.ts b/bin/test.ts index 4dc24f2..9b38db0 100644 --- a/bin/test.ts +++ b/bin/test.ts @@ -1,9 +1,6 @@ import { assert } from '@japa/assert' -import { pathToFileURL } from 'node:url' import { expectTypeOf } from '@japa/expect-type' -import { specReporter } from '@japa/spec-reporter' -import { runFailedTests } from '@japa/run-failed-tests' -import { processCliArgs, configure, run } from '@japa/runner' +import { processCLIArgs, configure, run } from '@japa/runner' /* |-------------------------------------------------------------------------- @@ -18,23 +15,10 @@ import { processCliArgs, configure, run } from '@japa/runner' | | Please consult japa.dev/runner-config for the config docs. */ +processCLIArgs(process.argv.splice(2)) configure({ - ...processCliArgs(process.argv.slice(2)), - ...{ - files: ['tests/**/*.spec.ts'], - plugins: [ - assert(), - runFailedTests(), - expectTypeOf(), - (_, __, { TestContext }) => { - TestContext.macro('sleep', function (time: number) { - return new Promise((resolve) => setTimeout(resolve, time)) - }) - }, - ], - reporters: [specReporter()], - importer: (filePath: string) => import(pathToFileURL(filePath).href), - }, + files: ['tests/**/*.spec.ts'], + plugins: [assert(), expectTypeOf()], }) /* diff --git a/package.json b/package.json index af035b1..d839e7b 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,9 @@ "@commitlint/cli": "^17.6.6", "@commitlint/config-conventional": "^17.6.6", "@fastify/middie": "^8.3.0", - "@japa/assert": "^1.4.1", - "@japa/expect-type": "^1.0.3", - "@japa/run-failed-tests": "^1.1.1", - "@japa/runner": "^2.5.1", - "@japa/spec-reporter": "^1.3.3", + "@japa/assert": "^2.0.0-1", + "@japa/expect-type": "^2.0.0-0", + "@japa/runner": "^3.0.0-3", "@swc/core": "^1.3.67", "@types/accepts": "^1.3.5", "@types/content-disposition": "^0.5.5", diff --git a/tests/cookies/serializer.spec.ts b/tests/cookies/serializer.spec.ts index 11ba9d7..dd521cc 100644 --- a/tests/cookies/serializer.spec.ts +++ b/tests/cookies/serializer.spec.ts @@ -8,6 +8,7 @@ */ import { test } from '@japa/runner' +import { setTimeout } from 'node:timers/promises' import { base64, MessageBuilder } from '@poppinss/utils' import { EncryptionFactory } from '@adonisjs/encryption/factories' @@ -81,13 +82,13 @@ test.group('Cookie | serialize', () => { assert.equal(options, `HttpOnly`) }) - test('invoke expires callback when defined as a function', async ({ assert, sleep }) => { + test('invoke expires callback when defined as a function', async ({ assert }) => { const config = { expires: () => new Date() } const serializer = new CookieSerializer(encryption) const serialized = serializer.encode('username', 'virk', config) - await sleep(1000) + await setTimeout(1000) const serialized1 = serializer.encode('username', 'virk', config) assert.notEqual(serialized, serialized1) })