Skip to content

Commit

Permalink
fix: add dispose options to withLocalFixture (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
matangeorgi authored Aug 3, 2023
1 parent 8ab085a commit b227d78
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/test-kit/src/with-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export function withFeature(withFeatureOptions: IWithFeatureOptions = {}) {

return { page: featurePage, response, getMetrics };
},
disposeAfter: dispose,
};
}

Expand Down
11 changes: 3 additions & 8 deletions packages/test-kit/src/with-local-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawnSync, SpawnSyncOptions } from 'child_process';
import fs from '@file-services/node';
import { IFeatureExecutionOptions, IWithFeatureOptions, withFeature } from './with-feature';
import { createTempDirectorySync } from 'create-temp-directory';
import { disposeAfter } from '@wixc3/testing';
import { DISPOSE_OF_TEMP_DIRS } from '@wixc3/testing-node';

export interface IWithLocalFixtureOptions extends IWithFeatureOptions {
fixturePath?: string;
Expand All @@ -13,7 +13,7 @@ export interface IWithLocalFixtureOptions extends IWithFeatureOptions {
* and optionally copies a fixture to it as a "project".
*/
export function withLocalFixture(suiteOptions: IWithLocalFixtureOptions) {
const { getLoadedFeature: originalGetLoadedFeature } = withFeature(suiteOptions);
const { getLoadedFeature: originalGetLoadedFeature, disposeAfter } = withFeature(suiteOptions);

async function getLoadedFeature(testOptions: IWithLocalFixtureOptions = suiteOptions) {
const { fixturePath = suiteOptions.fixturePath, runOptions = suiteOptions.runOptions } = testOptions;
Expand All @@ -24,12 +24,7 @@ export function withLocalFixture(suiteOptions: IWithLocalFixtureOptions) {
}

const { path: projectPath, remove } = createTempDirectorySync('local-test');
const { persist } = testOptions;
if (persist) {
after(() => remove());
} else {
disposeAfter(() => remove());
}
disposeAfter(() => remove(), { group: DISPOSE_OF_TEMP_DIRS });

if (fixturePath) {
await fs.promises.copyDirectory(fixturePath, projectPath);
Expand Down

0 comments on commit b227d78

Please sign in to comment.