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

improve and speedup circle ci setup #164

Merged
merged 2 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .testing/cache_build_and_dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

const path = require('path');
const spawn = require('child_process').spawn;
const baseDir = path.resolve(__dirname, '../');
const srcDir = baseDir;

const cacheMeteor = function() {
console.log('Caching build & dependencies (can take a while the first time)');
const childProcess = spawn('meteor', ['--raw-logs'], {
cwd: srcDir,
env: process.env
});
childProcess.stdout.setEncoding('utf8');
childProcess.stderr.setEncoding('utf8');
childProcess.stdout.on('data', function(line) {
process.stdout.write(line);
});
childProcess.stderr.on('data', function(line) {
process.stderr.write(line);
});
const exitAfterBuild = function exitAfterBuild(line) {
if (line.indexOf('App running at') !== -1) {
childProcess.kill();
console.log('Done caching build & dependencies');
} else if (
line.indexOf('Your application is crashing') !== -1 ||
line.indexOf('Errors prevented startup') !== -1) {
childProcess.kill();
console.error('There were issues whilst trying to cache build & dependencies');
throw new Error(line);
}
};
childProcess.stdout.on('data', exitAfterBuild);
childProcess.stderr.on('data', exitAfterBuild);
};

cacheMeteor();
3 changes: 3 additions & 0 deletions .testing/cache_build_and_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export MONGO_URL="mongodb://localhost:27017/cache"
echo "Running meteor to cache it …"
node ./.testing/cache_build_and_dependencies.js
3 changes: 3 additions & 0 deletions .testing/cache_meteor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cache Meteor
if [ -d ~/.meteor ]; then sudo ln -s ~/.meteor/meteor /usr/local/bin/meteor; fi
if [ ! -e $HOME/.meteor/meteor ]; then curl https://install.meteor.com | sh; fi
4 changes: 4 additions & 0 deletions .testing/cache_npm_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Cache npm deps
if [ ! -e /home/ubuntu/nvm/versions/node/v5.2.0/lib/node_modules/chimp/bin/chimp.js ]; then npm install -g chimp; fi
if [ ! -e /home/ubuntu/nvm/versions/node/v5.2.0/lib/node_modules/spacejam/bin/spacejam ]; then npm install -g spacejam; fi
npm install
59 changes: 59 additions & 0 deletions .testing/chimp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
"use strict";

var path = require('path');
var extend = require('util')._extend;
var baseDir = path.resolve(__dirname, '../');
var srcDir = path.resolve(baseDir);
var source = require(srcDir + '/node_modules/shell-source');
var processes = require('./processes.js');
var isCi = process.argv[2] === '--ci';

var startTestApp = function(onStarted, options) {
return processes.start({
name: 'Test App',
command: 'meteor --port=3100',
waitForMessage: 'App running at: http://localhost:3100',
options: {
cwd: srcDir,
env: extend(process.env, options)
}
}, function() {
console.log("Test app is running …");
onStarted();
});
};

var startChimpWatch = function() {
processes.start({
name: 'Chimp Watch',
command: 'chimp --ddp=http://localhost:3100 --watch --path=tests --mocha --chai --browser=chrome',
options: { cwd: baseDir }
});
};

var startChimpCi = function() {
var command = 'chimp --ddp=http://localhost:3100 --path=tests --browser=chrome --mocha --chai';
processes.start({
name: 'Chimp CI',
command: command,
options: { cwd: baseDir }
});
};

if (isCi) {
// CI mode -> run once
if (process.env.CIRCLECI) {
startTestApp(startChimpCi);
} else {
// Use a different db for local ci testing to avoid nuking of the dev db
startTestApp(startChimpCi, {
MONGO_URL: 'mongodb://localhost:3001/chimp_db'
});
}
} else {
// DEV mode -> watch
startTestApp(startChimpWatch, {
MONGO_URL: 'mongodb://localhost:3001/chimp_db'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is causing errors for me when I run ./tests/acceptance_run or ./tests/acceptance_watch. If I comment it out, the tests run fine.

Any ideas?

W20160802-13:09:00.524(-7)? (STDERR)
W20160802-13:09:00.525(-7)? (STDERR) /Users/noah/.meteor/packages/meteor-tool/.1.3.4_4.l7vwzg++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:313
W20160802-13:09:00.525(-7)? (STDERR)                        throw(ex);
W20160802-13:09:00.525(-7)? (STDERR)                              ^
W20160802-13:09:00.676(-7)? (STDERR) Error: failed to connect to [localhost:3001]
W20160802-13:09:00.676(-7)? (STDERR)     at Object.Future.wait (/Users/noah/.meteor/packages/meteor-tool/.1.3.4_4.l7vwzg++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:449:15)
W20160802-13:09:00.676(-7)? (STDERR)     at new MongoConnection (packages/mongo/mongo_driver.js:213:27)
W20160802-13:09:00.677(-7)? (STDERR)     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:16)
W20160802-13:09:00.677(-7)? (STDERR)     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:10)
W20160802-13:09:00.678(-7)? (STDERR)     at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
W20160802-13:09:00.678(-7)? (STDERR)     at new Mongo.Collection (packages/mongo/collection.js:103:40)
W20160802-13:09:00.678(-7)? (STDERR)     at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
W20160802-13:09:00.678(-7)? (STDERR)     at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)
W20160802-13:09:00.678(-7)? (STDERR)     at meteorInstall.node_modules.meteor.accounts-base.server_main.js (packages/accounts-base/server_main.js:9:12)
W20160802-13:09:00.679(-7)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
W20160802-13:09:00.679(-7)? (STDERR)     - - - - -
W20160802-13:09:00.679(-7)? (STDERR)     at [object Object].<anonymous> (/Users/noah/.meteor/packages/npm-mongo/.1.4.45.1n9eimd++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/server.js:556:74)
W20160802-13:09:00.679(-7)? (STDERR)     at [object Object].emit (events.js:106:17)
W20160802-13:09:00.679(-7)? (STDERR)     at [object Object].<anonymous> (/Users/noah/.meteor/packages/npm-mongo/.1.4.45.1n9eimd++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
W20160802-13:09:00.680(-7)? (STDERR)     at [object Object].emit (events.js:98:17)
W20160802-13:09:00.680(-7)? (STDERR)     at Socket.<anonymous> (/Users/noah/.meteor/packages/npm-mongo/.1.4.45.1n9eimd++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
W20160802-13:09:00.680(-7)? (STDERR)     at Socket.emit (events.js:95:17)
W20160802-13:09:00.680(-7)? (STDERR)     at net.js:441:14
W20160802-13:09:00.681(-7)? (STDERR)     at process._tickCallback (node.js:458:13)

Copy link
Contributor Author

@DominikGuzei DominikGuzei Aug 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you run the tests locally on your machine, you have to start the "normal" app first – this is done because otherwise the testing environment would override your local DB everytime. What we do here is this: the normal app is started and then the testing app uses the special Meteor MongoDB server to setup a chimp_db on the same mongo instance. This simplifies the setup because you do not need to have a standalone mongo installed and setup correctly locally.

So do this:
meteor

wait until the app runs, then in a different terminal:
./tests/acceptance_run or ./tests/acceptance_watch

});
}
45 changes: 45 additions & 0 deletions .testing/processes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";
var fs = require('fs');
var exec = require('child_process').exec;
var processes = [];

/**
* Helper function to start a process and listen for
* specific stdout console output and invoke a callback.
* This is used in this case to listen when the normal dev
* app started its mongoDb, so we can reuse that for the test app.
*/
module.exports = {
start: function(opts, callback) {
var proc = exec(
opts.command,
opts.options
);
if (opts.waitForMessage) {
proc.stdout.on('data', function waitForMessage(data) {
if (data.toString().match(opts.waitForMessage)) {
if (callback) {
callback();
}
}
});
}
if (!opts.silent) {
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
}
if (opts.logFile) {
var logStream = fs.createWriteStream(opts.logFile, {flags: 'a'});
proc.stdout.pipe(logStream);
proc.stderr.pipe(logStream);
}
proc.on('close', function(code) {
console.log(opts.name, 'exited with code ' + code);
for (var i = 0; i < processes.length; i += 1) {
processes[i].kill();
}
process.exit(code);
});
processes.push(proc);
}
};
22 changes: 18 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
machine:
node:
version: 0.10.40
version: 5.2.0
dependencies:
cache_directories:
- "~/.npm"
- "~/.meteor"
- "node_modules"
- "./.meteor/local/build"
- "./.meteor/local/bundler-cache"
- "./.meteor/local/isopacks"
- "./.meteor/local/plugin-cache"
- "/home/ubuntu/nvm/versions/node/v5.2.0/bin"
- "/home/ubuntu/nvm/versions/node/v5.2.0/lib/node_modules"
override:
- curl https://install.meteor.com | /bin/sh
- meteor npm install
- ./.testing/cache_meteor.sh
- ./.testing/cache_npm_dependencies.sh
- ./.testing/cache_build_and_dependencies.sh
- chimp --path=features # Cache chimp deps by running it without any tests
checkout:
post:
- git submodule update --init
test:
pre:
- mkdir -p $CIRCLE_TEST_REPORTS/cucumber
override:
- meteor npm test
- ./tests/acceptance_run
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"test-app-watch": "meteor test --full-app --driver-package practicalmeteor:mocha",
"test-watch-terminal": "TEST_WATCH=1 meteor test --driver-package dispatch:mocha-phantomjs",
"test-app-watch-terminal": "TEST_WATCH=1 meteor test --full-app --driver-package dispatch:mocha-phantomjs",
"lint": "eslint .",
"chimp-watch": "chimp --ddp=http://localhost:3000 --watch --mocha --path=tests"
"lint": "eslint ."
},
"dependencies": {
"autoprefixer": "^6.3.7",
Expand All @@ -23,7 +22,8 @@
"eslint-plugin-import": "^1.10.3",
"eslint-plugin-jsx-a11y": "^1.5.3",
"eslint-plugin-meteor": "^3.6.0",
"eslint-plugin-react": "^5.2.2"
"eslint-plugin-react": "^5.2.2",
"shell-source": "^1.1.0"
},
"eslintConfig": {
"parser": "babel-eslint",
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
node ./.testing/chimp.js --ci
2 changes: 2 additions & 0 deletions tests/acceptance_watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
node ./.testing/chimp.js
4 changes: 2 additions & 2 deletions tests/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/* globals browser assert */

const countLists = () => {
browser.waitForExist('.list-todo');
browser.waitForVisible('.list-todo', 5000);
const elements = browser.elements('.list-todo');
return elements.value.length;
};

describe('list ui', () => {
beforeEach(() => {
browser.url('http://localhost:3000');
browser.url('http://localhost:3100');
});

it('can create a list @watch', () => {
Expand Down