Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
feat: Add tests for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
indebanvdhamer committed Aug 31, 2018
1 parent f9f7c49 commit 63d0388
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 3 deletions.
6 changes: 3 additions & 3 deletions getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const resolve = () => ({
}
});

const entry = (ent = './src/index.js') => ent;
const entry = (ent = './src/index.js', cwd = process.cwd()) => path.resolve(cwd, ent);

const optimization = op => op || optimizations();

Expand Down Expand Up @@ -118,8 +118,8 @@ const getConfig = args => {
...configFile,
};

const checkOption = checkFile(configFile);
logIntro(config);
const checkOption = checkFile(config);
config.env !== 'test' && logIntro(config);

const moduleRules = () => ({
rules: applyLoaders(config.preset.loaders.map(x => x(config))),
Expand Down
4 changes: 4 additions & 0 deletions tests/__mocks__/@cycle/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
makeDOMDriver: () => {},
h1: () => {},
};
3 changes: 3 additions & 0 deletions tests/__mocks__/@cycle/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
run: () => {},
};
1 change: 1 addition & 0 deletions tests/__mocks__/babel-runtime/core-js/json/stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = () => {};
1 change: 1 addition & 0 deletions tests/__mocks__/react-dom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions tests/__mocks__/react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
3 changes: 3 additions & 0 deletions tests/__mocks__/xstream/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
periodic: () => [],
};
21 changes: 21 additions & 0 deletions tests/samples/samples.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const {runner} = require('./testRunner');

runner({
dir: 'cyclejs',
name: 'Cyclejs',
});

runner({
dir: 'react-and-favicon',
name: 'React and favicon',
});

runner({
dir: 'react-and-graphql',
name: 'React and GraphQL',
});

runner({
dir: 'react-and-sass',
name: 'React and SCSS',
});
52 changes: 52 additions & 0 deletions tests/samples/testRunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable no-console */
const path = require('path');
const webpack = require('webpack');
const MemoryFS = require('memory-fs');
const {getConfig} = require('../../getConfig');

const runner = ({dir, name, config}) => {
const fs = new MemoryFS();

const mocks = path.join(__dirname, '../__mocks__');
const sample = (p = '') => path.join(__dirname, `../../samples/${dir}`, p);

const build = (args, cb) => {
const config = getConfig(args);
const compiler = webpack({
...config,
entry: path.resolve(args.cwd, './src/index'),
resolve: {
...config.resolve,
modules: [mocks]
}
});

compiler.outputFileSystem = fs;

compiler.run((err, stats) => {
if(err) {
throw new Error(err);
}
if(stats.hasErrors()) {
console.log(stats.toString('errors-only'));
}
cb();
});
};

describe(`${name} sample`, () => {
it('should not crash when building for development', done => {
build({
env: 'test',
mode: 'development',
cwd: sample(),
config: sample('.webpacker.js'),
...config,
}, done);
});
});
};

module.exports = {
runner,
};

0 comments on commit 63d0388

Please sign in to comment.