Skip to content

Commit

Permalink
feat: empty output folder in config (#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed May 28, 2023
1 parent dfec1d9 commit 5b8c3b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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

0 comments on commit 5b8c3b7

Please sign in to comment.