Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: empty output folder in config #3604

Merged
merged 1 commit into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Config = require('./config');
const event = require('./event');
const runHook = require('./hooks');
const output = require('./output');
const { emptyFolder } = require('./utils');

/**
* CodeceptJS runner
Expand Down Expand Up @@ -66,6 +67,8 @@ class Codecept {
global.codecept_dir = dir;
global.output_dir = fsPath.resolve(dir, this.config.output);

if (this.config.emptyOutputFolder) emptyFolder(global.output_dir);

if (!this.config.noGlobals) {
global.Helper = global.codecept_helper = require('@codeceptjs/helper');
global.actor = global.codecept_actor = require('./actor');
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,7 @@ module.exports.isNotSet = function (obj) {
if (obj === undefined) return true;
return false;
};

module.exports.emptyFolder = async (directoryPath) => {
require('child_process').execSync(`rm -rf ${directoryPath}/*`);
};
8 changes: 8 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ declare namespace CodeceptJS {
* ```
*/
output: string;
/**
* empty output folder for next run
*
* ```js
* emptyOutputFolder: true
* ```
*/
emptyOutputFolder?: boolean;
/**
* Pattern to filter tests by name.
* This option is useful if you plan to use multiple configs for different environments.
Expand Down