This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
improve and speedup circle ci setup #164
Merged
tmeasday
merged 2 commits into
meteor:master
from
DominikGuzei:chore/fix-circle-ci-tests
Jul 18, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
node ./.testing/chimp.js --ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
node ./.testing/chimp.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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