UNPKG

1.31 kBJavaScriptView Raw
1const path = require('path');
2const fs = require('fs');
3const setup = require('./test-setup');
4const root = process.cwd();
5
6/**
7 * A function to configure Wallaby for your package.
8 * @param {object} config The configuration settings for Wallaby
9 * @param {string} config.name
10 * @param {boolean} config.enableReact
11 * @param {object[]} config.include
12 */
13module.exports = function (config) {
14 const packageJsonPath = path.resolve(root, 'package.json');
15 if (!fs.existsSync(packageJsonPath)) { throw new Error('Unable to find package.json file for this package.'); }
16 const { name } = require(packageJsonPath);
17 config = {
18 name,
19 include: [],
20 ...config,
21 };
22 return function () {
23 return {
24 name: config.name,
25 files: [
26 { pattern: 'package.json', load: false },
27 '!src/**/*.tests.ts?(x)',
28 { pattern: 'src/**/*.ts?(x)', load: false },
29 ...config.include,
30 ],
31 tests: [
32 { pattern: 'src/**/*.tests.ts?(x)' },
33 ],
34 testFramework: 'mocha',
35 env: {
36 type: 'node',
37 },
38 workers: {
39 initial: 6,
40 regular: 3,
41 },
42 debug: true,
43 setup: eval('(function () { (' + setup.toString() + ')(' + JSON.stringify(config) + '); })'),
44 };
45 };
46};