1

I want to create a file of certain size (20MB) in the cypress test.

I don't want to include a real file in the fixtures as it would clutter my repository.

I can't use an environment file as this would be run locally and on CI. It needs to be platform independent.

Is there a way I can do this in the test without the usage of system scripts? Like in this question Creating an empty file of a certain size?

Zoidy
  • 362
  • 4
  • 21

1 Answers1

2

Solved it by using cy.task.

in my test

cy.task('createFile', 'fileName').then( .... test code)

in plugins/index.js

const fs = require('fs');
on('task', {
   createFile(fileName) {
      return new Promise((done) => {
         const fh = fs.openSync(config.fileName, 'w');
         fs.writeSync(fh, 'ok', Math.max(0, DESIRED_SIZE));
         fs.closeSync(fh);
         done(true);
      });
   }
});
Zoidy
  • 362
  • 4
  • 21