const { spawn } = require('child_process');
const fs = require('fs');

const env = { ...process.env, BASE_URL: 'http://127.0.0.1:3001' };
const child = spawn('npx.cmd', ['playwright', 'test', 'tests/e2e'], { env, shell: true });

const out = fs.createWriteStream('test_node_output.txt');

child.stdout.on('data', data => {
  out.write(data);
  console.log(data.toString());
});
child.stderr.on('data', data => {
  out.write(data);
  console.error(data.toString());
});
child.on('close', code => {
  console.log(`child process exited with code ${code}`);
  out.end();
});
