CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

How To Clear Output Folder That Saves The Failed Cases Snapshot

Open ninpop25 opened this issue 8 years ago • 5 comments

I am running my test cases on client server Via Jenkins and I want that each time when I Run my Tests then Output folder is cleaned and then when tests finishes all those failed cases snapshots are attached and sent in Build Report Email

What do you get instead?

Provide console output if related. Use --verbose mode for more details.

# paste output here

Provide test source code if related

// paste test

Details

  • CodeceptJS version:
  • NodeJS Version:
  • Operating System:
  • Protractor || WebDriverIO || Nightmare version (if related)
  • Configuration file:
# paste suite config here

ninpop25 avatar Jan 11 '18 08:01 ninpop25

This can be done with Jenkins without CodeceptJS

Just add rm -rf tests/output/* before executing tests.

And please don't spam in Twitter. That doesn't sound like a good manner.

DavertMik avatar Jan 11 '18 23:01 DavertMik

@DavertMik : Thanks for reply,I forgot to inform you that my Server is Windows 10 Machine,so request you to please tell me the command for windows that deletes all Sub Folders and Files Inside Output Directory .

Also please let me know that how this Output folder that contains snapshots ,will be attached in Build Report mail?

I am really sorry for Spamming twitter ,will not do it again.

Thanks once again for quick response

ninpop25 avatar Jan 12 '18 08:01 ninpop25

FYI Here's an example on how I just set this up using the bootstrap configuration:

"bootstrap": function(done) {
    try {
        const {ctimeMs} = fs.statSync(OUTPUT_PATH);
        fs.renameSync(OUTPUT_PATH, `${OUTPUT_PATH}_${ctimeMs}`);
    } catch(error) {
        console.error('Could not rename output path');
        console.log(error);
    }

    done();
},

I choose to rename the old output folder instead of deleting it, deleting it might require using glob or launching a sub-process that is aware of the OS.

OUTPUT_PATH is a variable defined on top of the configuration file, that is used both in this bootstrap function and in the output configuration. Not sure if there is a way to get the current configuration of Codecept as a parameter to the bootstrap function?

schmkr avatar Jan 02 '19 09:01 schmkr

🤔 Forget that, it seems doing this in the bootstrap function, the output dir is renamed during the run 😞

schmkr avatar Jan 02 '19 09:01 schmkr

Here is how I did it for 3.0.2, in case someone comes here from search engine:

// codecept.conf.js
const rimraf = require("rimraf");
const outputFolder = "./test/e2e/bdd/.tmp";

exports.config = {
  // ... irrelevant code
  output: outputFolder,
  async bootstrap() {
    await new Promise((resolve, reject) => {
      rimraf(outputFolder, (err) => {
        if (err) {
          reject(err);
        } else {
          resolve();
        }
      });
    });
  },
  // ... irrelevant code
};

aesyondu avatar Nov 27 '20 14:11 aesyondu