From 4eba651c3d5520b09002b837ee54eae75475bce7 Mon Sep 17 00:00:00 2001 From: Elliot DeNolf Date: Sat, 16 Mar 2024 06:59:56 -0400 Subject: [PATCH] test: refine testHooks --- test/testHooks.ts | 16 +++++++--------- tsconfig.json | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/testHooks.ts b/test/testHooks.ts index 70ad8ad14e..84d451f994 100644 --- a/test/testHooks.ts +++ b/test/testHooks.ts @@ -1,10 +1,11 @@ import { existsSync, promises } from 'fs' import json5 from 'json5' -import { dirname, resolve } from 'path' +import path from 'path' import { fileURLToPath } from 'url' const { readFile, writeFile, rm } = promises -const { parse } = json5 +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) type TestHooks = { afterTest: () => Promise @@ -12,13 +13,10 @@ type TestHooks = { } export const createTestHooks = async (testSuiteName = '_community'): Promise => { - const __filename = fileURLToPath(import.meta.url) - const __dirname = dirname(__filename) - console.log('\nUsing config:', testSuiteName, '\n') - const tsConfigPath = resolve(__dirname, '..', 'tsconfig.json') - const tsConfig = await parse(await readFile(tsConfigPath, 'utf8')) + const tsConfigPath = path.resolve(dirname, '..', 'tsconfig.json') + const tsConfig = await json5.parse(await readFile(tsConfigPath, 'utf8')) const originalPayloadConfigTsValue = tsConfig.compilerOptions.paths['@payload-config'] ?? './test/_community/config.ts' @@ -28,7 +26,7 @@ export const createTestHooks = async (testSuiteName = '_community'): Promise { // Delete next webpack cache - const nextWebpackCache = resolve(__dirname, '..', '.next/cache/webpack') + const nextWebpackCache = path.resolve(dirname, '..', '.next/cache/webpack') if (existsSync(nextWebpackCache)) { await rm(nextWebpackCache, { recursive: true }) } @@ -37,7 +35,7 @@ export const createTestHooks = async (testSuiteName = '_community'): Promise