Skip to content

Commit

Permalink
Fix travis build
Browse files Browse the repository at this point in the history
  • Loading branch information
geowarin committed Jun 25, 2016
1 parent 5377d11 commit 451f54a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ cache:
- node_modules

after_success: npm run coverage

# for nightmarejs
addons:
apt:
packages:
- xvfb
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- npm install
6 changes: 3 additions & 3 deletions lib/babel/createBabelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
const resolve = require('resolve');
const chalk = require('chalk');

function findReact () {
function findReact (basedir) {
try {
return resolve.sync('react', {basedir: process.cwd()});
return resolve.sync('react', {basedir});
} catch (e) {
throw new Error('Could not find react in your node_modules. Run npm install to fix the issue.');
}
}

module.exports = function createBabelConfig (context, isWebpack) {
const reactPath = findReact();
const reactPath = findReact(context.projectDir);
return {
presets: [
require.resolve('babel-preset-react'),
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function start (context, args) {

app.use(require('webpack-hot-middleware')(compiler));

app.listen(context.serverPort, 'localhost', (err) => {
app.listen(context.serverPort, '0.0.0.0', (err) => {
if (err) {
debug.log(err);
return;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"gitbook-cli": "^2.1.3",
"nightmare": "^2.5.2",
"nyc": "^6.4.4",
"portfinder": "^1.0.3",
"temp": "^0.8.3"
},
"nyc": {
Expand Down
37 changes: 27 additions & 10 deletions test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ const fs = require('fs');
const path = require('path');
const Nightmare = require('nightmare');
const {execSync} = require('child_process');
const deasync = require('deasync');
const findOpenPort = deasync(require('portfinder').getPort);

const test = require('ava');

function recursiveReaddir (root) {
function recursiveReaddir (root, includeFiles = true, includeDirs = false) {
const files = [root];
const results = [];

const addResult = (file, parent) => {
const relativeParent = path.relative(root, parent);
results.push(path.join(relativeParent, file));
};

while (files.length) {
const parent = files.pop();
let subFiles = fs.readdirSync(parent);
Expand All @@ -22,9 +29,11 @@ function recursiveReaddir (root) {
const fullPath = path.join(parent, file);
if (fs.statSync(fullPath).isDirectory()) {
files.push(fullPath);
} else {
const relativeParent = path.relative(root, parent);
results.push(path.join(relativeParent, file));
if (includeDirs) {
addResult(file, parent);
}
} else if (includeFiles) {
addResult(file, parent);
}
}
}
Expand All @@ -48,13 +57,17 @@ function toHaveFilesMatching (...regexps) {
)
}

expect.extend({toHaveFiles, toHaveFilesMatching});
function toHaveDirectories (...expectedDirs) {
const files = recursiveReaddir(this.actual, false, true);
expect(files).toInclude(...expectedDirs);
}

expect.extend({toHaveFiles, toHaveFilesMatching, toHaveDirectories});

function npmInstall (cwd) {
execSync('npm install', {cwd, stdio: ['ignore', 'ignore', 'pipe']})
execSync('npm install --cache-min 99999', {cwd, stdio: ['ignore', 'ignore', 'inherit']})
}


test.cb('Should init and run', t => {
// things do not work properly in tmp on mac
const tmp = temp.mkdirSync({dir: __dirname});
Expand All @@ -64,14 +77,18 @@ test.cb('Should init and run', t => {
expect(tmp).toHaveFiles('package.json', 'src/index.js');

npmInstall(tmp);
tarec(tmp, ['start']);
const nodeModulesDir = path.join(tmp, 'node_modules');
expect(nodeModulesDir).toHaveDirectories('react', 'react-dom');

const port = findOpenPort();
tarec(tmp, ['start', '-p', port]);

Nightmare()
.goto('http://localhost:3000')
.goto(`http://0.0.0.0:${port}`)
.wait(() => document.querySelector('h1').textContent === 'Hello')
.end()
.then(t.end);

});

test('Should init and build', () => {
Expand Down

0 comments on commit 451f54a

Please sign in to comment.