From 7dfb59664b87d30384bd3ce16ea5d939f0d99f8f Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Mon, 16 Oct 2023 23:56:45 -0400 Subject: [PATCH] Test cleanup --- src/bundle/html.test.ts | 3 +-- src/bundle/otto.spec.ts | 11 +---------- src/bundle/otto.test.ts | 4 ++-- src/bundle/otto/mac.test.ts | 3 +-- src/bundle/otto/windows.test.ts | 3 +-- src/util.spec.ts | 8 ++++++++ 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/bundle/html.test.ts b/src/bundle/html.test.ts index cc10106..96c32f7 100644 --- a/src/bundle/html.test.ts +++ b/src/bundle/html.test.ts @@ -2,10 +2,9 @@ import {describe, it} from 'node:test'; import {ok} from 'node:assert'; import {join as pathJoin} from 'node:path'; -import {fixtureFile} from '../util.spec'; +import {cleanBundlesDir, fixtureFile} from '../util.spec'; import {Bundle} from '../bundle'; -import {cleanBundlesDir} from './otto.spec'; import {BundleHtml} from './html'; const getDir = async (d: string) => cleanBundlesDir('html', d); diff --git a/src/bundle/otto.spec.ts b/src/bundle/otto.spec.ts index 6898ef4..52fcde7 100644 --- a/src/bundle/otto.spec.ts +++ b/src/bundle/otto.spec.ts @@ -1,20 +1,11 @@ import {basename, dirname, join as pathJoin} from 'node:path'; -import {mkdir, rm, writeFile} from 'node:fs/promises'; +import {mkdir, writeFile} from 'node:fs/promises'; import {trimExtension} from '../util'; import {ProjectorOttoDummy} from '../projector/otto.spec'; import {BundleOtto} from './otto'; -export const specBundlesPath = pathJoin('spec', 'bundles'); - -export async function cleanBundlesDir(...path: string[]) { - const dir = pathJoin(specBundlesPath, ...path); - await rm(dir, {recursive: true, force: true}); - await mkdir(dir, {recursive: true}); - return dir; -} - export class BundleOttoDummy extends BundleOtto { public readonly projector: ProjectorOttoDummy; diff --git a/src/bundle/otto.test.ts b/src/bundle/otto.test.ts index 3c08fe9..c41efcc 100644 --- a/src/bundle/otto.test.ts +++ b/src/bundle/otto.test.ts @@ -13,10 +13,10 @@ import {join as pathJoin, dirname} from 'node:path'; import {fsLchmod, fsLutimes} from '@shockpkg/archive-files'; -import {fixtureFile} from '../util.spec'; +import {cleanBundlesDir, fixtureFile} from '../util.spec'; import {Bundle} from '../bundle'; -import {BundleOttoDummy, cleanBundlesDir} from './otto.spec'; +import {BundleOttoDummy} from './otto.spec'; import {BundleOtto} from './otto'; const getDir = async (d: string) => cleanBundlesDir('otto', 'dummy', d); diff --git a/src/bundle/otto/mac.test.ts b/src/bundle/otto/mac.test.ts index eac56c1..b0fb83d 100644 --- a/src/bundle/otto/mac.test.ts +++ b/src/bundle/otto/mac.test.ts @@ -3,8 +3,7 @@ import {ok} from 'node:assert'; import {join as pathJoin} from 'node:path'; import {listSamples} from '../../projector/otto/mac.spec'; -import {cleanBundlesDir} from '../otto.spec'; -import {fixtureFile, getPackageFile} from '../../util.spec'; +import {cleanBundlesDir, fixtureFile, getPackageFile} from '../../util.spec'; import {BundleOtto} from '../otto'; import {BundleOttoMac} from './mac'; diff --git a/src/bundle/otto/windows.test.ts b/src/bundle/otto/windows.test.ts index 2dc26c4..16d7325 100644 --- a/src/bundle/otto/windows.test.ts +++ b/src/bundle/otto/windows.test.ts @@ -3,8 +3,7 @@ import {ok} from 'node:assert'; import {join as pathJoin} from 'node:path'; import {listSamples, versionStrings} from '../../projector/otto/windows.spec'; -import {cleanBundlesDir} from '../otto.spec'; -import {fixtureFile, getPackageFile} from '../../util.spec'; +import {cleanBundlesDir, fixtureFile, getPackageFile} from '../../util.spec'; import {BundleOtto} from '../otto'; import {BundleOttoWindows} from './windows'; diff --git a/src/util.spec.ts b/src/util.spec.ts index 30fd2ae..34329f7 100644 --- a/src/util.spec.ts +++ b/src/util.spec.ts @@ -16,6 +16,7 @@ export function shouldTest(name: string) { export const specFixturesPath = pathJoin('spec', 'fixtures'); export const specProjectorsPath = pathJoin('spec', 'projectors'); +export const specBundlesPath = pathJoin('spec', 'bundles'); export function fixtureFile(name: string) { return pathJoin(specFixturesPath, name); @@ -32,6 +33,13 @@ export async function cleanProjectorDir(...path: string[]) { return dir; } +export async function cleanBundlesDir(...path: string[]) { + const dir = pathJoin(specBundlesPath, ...path); + await rm(dir, {recursive: true, force: true}); + await mkdir(dir, {recursive: true}); + return dir; +} + let getInstalledPackagesCache: string[] | null = null; export function getInstalledPackagesSync() { if (!getInstalledPackagesCache) {