sindresorhus / gulp-mocha

Run Mocha tests
MIT License
375 stars 91 forks source link

Problems with 10 version #208

Closed burcadoruciprian closed 6 months ago

burcadoruciprian commented 6 months ago

Hello,

I have the following task which stopped working after upgrade to 10.0.0 version with error Error: No test files found: "test"

function adminServiceTests() {
  return src([
      'build/tests/server/_bootstrap.js',
      'build/tests/server/**/*.spec.js'
    ], { read: false})
    .pipe(mocha({
      timeout: 20000,
      reporter: mochaReporter
    }));
}

I have tracked down the issue with the way gulpPlugin is called. It's current implementation 0.3.0 is

export function gulpPlugin(name, onFile, {
    onFinish,
    supportsDirectories = false,
    supportsAnyType = false,
} = {}) {
    return transformStream(
        {
            objectMode: true,
        },
        async file => {
            if (!supportsAnyType) {
                if (file.isNull() && !(supportsDirectories && file.isDirectory())) {
                    return file;
                }
                if (file.isStream()) {
                    throw new PluginError(name, 'Streaming not supported');
                }
            }

            try {
                return await onFile(file);
            } catch (error) {
                throw new PluginError(name, error, {
                    fileName: file.path,
                    showStack: true,
                });
            }
        },
        onFinish && async function * (stream) {
            try {
                yield * onFinish(stream);
            } catch (error) {
                throw new PluginError(name, error, {showStack: true});
            }
        },
    );
}

Currently the callback will exit prematurely here (see bellow) because the file will be null ({read: false}), thus onFile callback is not executed which in turn accumulates the test files.

if (file.isNull() && !(supportsDirectories && file.isDirectory())) {
  return file;
}

To fix this, just call gulpPlugin with supportsAnyType option true

Thanks