sysgears / mochapack

Mocha test runner with integrated webpack precompiler
https://sysgears.github.io/mochapack/
MIT License
183 stars 28 forks source link

[Feature/help] running with child processes #11

Open andykais opened 5 years ago

andykais commented 5 years ago

Hi, thank you for maintaining this fork! I have a project that creates child processes from other webpack entrypoints. Minimally reproducible example:

// webpack.config.js
const path = require('path')

module.exports = {
  target: 'node',
  node: {
    dirname: true
  },
  mode: 'development',
  entry: {
    main: './src/main.js',
    child: './src/child.js'
  },
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: '[name].js'
  }
}
// test_sample.js
import {startFork} from './main';

describe('me', () => {
  it('test only', () => {
    console.log('forky')
    startFork();
  });
});
// src/main.js
import {fork} from 'child_process';

export const startFork = () => {
  console.log('starting fork');
  fork('./child.js');
};
// src/child.js
import * as path from 'path'

console.log('im a fork')

Running the tests with mochapack (or mocha-webpack) will fail because a fork (or any code that expects a physical file to work with from an entrypoint) cannot use the entrypoint.

npx mochapack test_sample.js
Error: Cannot find module '/Users/andrew/Code/development/sample-failure/build/child.js'

What is the course of action here? Is there a simple workaround? If not, this is a feature request that proposes actually writing code to the build folder, which is not something mochapack/mocha-webpack has done in the past

andykais commented 5 years ago

let me know if you prefer a repo to reproduce the problem, Im happy to make one!

larixer commented 5 years ago

@andykais I'm not sure I understand. Would you be willing to chat in a gitter room about this issue?

larixer commented 5 years ago

@andykais I have created gitter room for mochapack here: https://gitter.im/sysgears/mochapack

larixer commented 5 years ago

Thank you @andykais for raising this issue and having a chat about it. As per our chat conversation, it seems like a good idea to enable writing output to disk with some mochapack cli flag, so that we support both in-memory output mode and filesystem output mode. The relevant Pull Request for original mocha-webpack that can be of help to add back filesystem output support can be seen here: https://github.com/zinserjan/mocha-webpack/pull/83/files