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

Commit

Permalink
Bug 953099 - Use mocha for integration test on build system
Browse files Browse the repository at this point in the history
  • Loading branch information
yurenju committed Dec 25, 2013
1 parent 8f6489e commit 4cc6b3c
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 102 deletions.
16 changes: 15 additions & 1 deletion Makefile
Expand Up @@ -377,6 +377,15 @@ define BUILD_CONFIG
endef
export BUILD_CONFIG

define run-build-test
./node_modules/.bin/mocha \
--harmony \
--reporter spec \
--ui tdd \
--timeout 0 \
$(strip $1)
endef

# Generate profile/

$(PROFILE_FOLDER): preferences local-apps app-makefiles test-agent-config offline contacts extensions install-xulrunner-sdk .git/hooks/pre-commit $(PROFILE_FOLDER)/settings.json create-default-data $(PROFILE_FOLDER)/installed-extensions.json
Expand Down Expand Up @@ -645,7 +654,7 @@ endif

# this lists the programs we need in the Makefile and that are installed by npm

NPM_INSTALLED_PROGRAMS = node_modules/.bin/mozilla-download node_modules/.bin/jshint
NPM_INSTALLED_PROGRAMS = node_modules/.bin/mozilla-download node_modules/.bin/jshint node_modules/.bin/mocha
$(NPM_INSTALLED_PROGRAMS): package.json
npm install --registry $(NPM_REGISTRY)
touch $(NPM_INSTALLED_PROGRAMS)
Expand Down Expand Up @@ -957,3 +966,8 @@ really-clean: clean
adb-remount:
$(ADB) remount

build-test-unit: $(NPM_INSTALLED_PROGRAMS)
@$(call run-build-test, $(shell find build/test/unit/*.test.js))

build-test-integration: $(NPM_INSTALLED_PROGRAMS)
@$(call run-build-test, $(shell find build/test/integration/*.test.js))
110 changes: 110 additions & 0 deletions build/test/integration/build.test.js
@@ -0,0 +1,110 @@
var exec = require('child_process').exec;
var assert = require('chai').assert;
var rmrf = require('rimraf').sync;
var download = require('download');
var async = require('async');
var fs = require('fs');
var path = require('path');

function checkError(error, stdout, stderr) {
if (error) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
console.log('error: ' + error);
}
assert.equal(error, null);
}

suite('Build Integration tests', function() {
var localesDir = 'tmplocales';

suiteSetup(function() {
rmrf('profile');
rmrf('profile-debug');
rmrf(localesDir);
});

test('make without rule & variable', function(done) {
exec('make', function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
});
});

test('make with PRODUCTION=1', function(done) {
exec('PRODUCTION=1 make', function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
});
});

test('make with SIMULATOR=1', function(done) {
exec('SIMULATOR=1 make', function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
});
});

test('make with DEBUG=1', function(done) {
exec('DEBUG=1 make', function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
});
});

test('make with MOZILLA_OFFICIAL=1', function(done) {
exec('MOZILLA_OFFICIAL=1 make', function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
});
});

test('make with GAIA_DISTRIBUTION_DIR=distribution_tablet', function(done) {
exec('GAIA_DISTRIBUTION_DIR=distribution_tablet make',
function(error, stdout, stderr) {
checkError(error, stdout, stderr);
done();
}
);
});

test('make with l10n configuration', function(done) {
var locales = ['en-US', 'zh-CN'];
var localesFileObj = {};
var tasks = locales.map(function(locale) {
localesFileObj[locale] = '';
return function (callback) {
var dir = path.join(localesDir, locale);
fs.mkdirSync(dir);
var url = 'http://hg.mozilla.org/gaia-l10n/' + locale +
'/archive/tip.tar.gz';
var dl = download(url, dir, {extract: true, strip: 1});
dl.once('close', function() {
callback();
});
};
});

tasks.push(function(callback) {
localesFilePath = path.join(localesDir, 'languages.json');
fs.writeFileSync(localesFilePath, JSON.stringify(localesFileObj));
command = 'LOCALES_FILE=' + localesFilePath +
' LOCALE_BASEDIR=' + localesDir +
' make';
exec(command, function(error, stdout, stderr) {
checkError(error, stdout, stderr);
callback();
});
});
fs.mkdirSync(localesDir);
async.series(tasks, function() {
rmrf(localesDir);
done();
});
});

teardown(function() {
rmrf('profile');
rmrf('profile-debug');
});
});
Expand Up @@ -11,7 +11,7 @@ suite('applications-data', function() {
var app;
setup(function() {
app = proxyquire.noCallThru().load(
'./../applications-data', {
'../../applications-data', {
'./utils': mockUtils,
'./webapp-manifests': mockWebappManifests
});
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -25,6 +25,9 @@
"node-static": "0.6.9",
"travis-project-jobs": "0.0.1",
"chai": "~1.4.2",
"proxyquire": "~0.4"
"proxyquire": "~0.4",
"rimraf": "2.2.5",
"download": "0.1.7",
"async": "0.2.9"
}
}
101 changes: 2 additions & 99 deletions tests/travis_ci/build_tests/script
@@ -1,101 +1,4 @@
#! /bin/bash

# Exit if we encounter any bug
set -e

debugmessage=''

gaia_clear () {
make clean &> /dev/null
}

error_handler () {
printf '\e[41;30m x ---- fail\e[40;37m \n'
printf $debugmessage
}

pass_handler () {
printf '\e[42;30m v ---- pass\e[40;37m \n'
}

unit_test () {
REPORTER=dot
testfiles=$(find build/test/*.test.js)
echo $testfiles
./node_modules/.bin/mocha \
--harmony \
--reporter $REPORTER \
--ui tdd \
$testfiles
}


trap error_handler ERR

# Store all the distributions folder here
distributions=(distribution_tablet)

# Store locales test language
locales=(en-US zh-CN)

# Address of locale file
locale_url=http://hg.mozilla.org/gaia-l10n/LOCALEURL/archive/tip.tar.gz

printf 'Running unit test ...'
unit_test
pass_handler

printf 'make ...'
gaia_clear
debugmessage=$(make)
pass_handler

printf 'PRODUCTION=1 make ... '
gaia_clear
debugmessage=$(PRODUCTION=1 make)
pass_handler

printf 'SIMULATOR=1 make ...'
gaia_clear
debugmessage=$(SIMULATOR=1 make)
pass_handler

printf 'DEBUG=1 make ...'
gaia_clear
debugmessage=$(DEBUG=1 make)
pass_handler

printf 'GAIA_DISTRIBUTION_DIR=<distribution> make ...'
for distribution in ${distributions[@]}; do
gaia_clear
printf '\n -DISTRIBUTION='$distribution' ... '
debugmessage=$(GAIA_DISTRIBUTION_DIR=$distribution make)
pass_handler
done

printf 'MOZILLA_OFFICIAL=1 make ...'
gaia_clear
debugmessage=$(MOZILLA_OFFICIAL=1 make)
pass_handler

printf 'LOCALES_FILE=<PATH_OF_LOCALES_FILE> LOCALE_BASEDIR=<PATH_OF_LOCALE_BASEDIR> make ...\n'
gaia_clear
if [ -d 'templocale' ]; then
rm -rf templocale/*
else
mkdir templocale
fi

pushd templocale &> /dev/null
touch locale.json
localeJSON='{'
for locale in ${locales[@]}; do
mkdir $locale
localeJSON+="\"$locale\": \"$locale\","
curl -s ${locale_url/LOCALEURL/$locale} | tar xvz --strip-components=1 --directory=$locale &> /dev/null
done
localeJSON="${localeJSON%?}}"
echo $localeJSON >> locale.json
popd &> /dev/null
debugmessage=$(LOCALES_FILE=templocale/locale.json LOCALE_BASEDIR=templocale make)
pass_handler
make build-test-unit
make build-test-integration

0 comments on commit 4cc6b3c

Please sign in to comment.