Skip to content

Commit

Permalink
add build test for css plugin. refs #6
Browse files Browse the repository at this point in the history
  • Loading branch information
clmath committed Apr 22, 2015
1 parent 7f11fc2 commit dbdd70c
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ module.exports = function (grunt) {
// Travis build
grunt.registerTask("travis", ["jshint", "test:remote"]);

grunt.registerTask("testBuild", "Run the builds used by the functional tests", function () {
grunt.registerTask("testBuild", "Run the build used by the functional test", function (test) {
var done = this.async();

var appRootDir = "tests/functional/jqueryApp";
var appRootDir = "tests/functional/" + test + "App";

function npmInstall(error, bowerResults) {
if (error !== null) {
Expand Down Expand Up @@ -168,7 +168,8 @@ module.exports = function (grunt) {
}

// First create the test builds. These are referenced from the intern tests.
grunt.task.run("testBuild");
grunt.task.run("testBuild:css");
grunt.task.run("testBuild:jquery");

// Then run the intern tests.
grunt.task.run("intern:" + target);
Expand Down
1 change: 1 addition & 0 deletions tests/functional/all.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Listing of all the plugin functional tests
define([
"./cssBuild",
"./jqueryBuild",
"./jqueryScript"
]);
3 changes: 3 additions & 0 deletions tests/functional/cssApp/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
90 changes: 90 additions & 0 deletions tests/functional/cssApp/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Gruntfile for building layer including src.js and the jquery modules it references
module.exports = function (grunt) {
"use strict";

grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-amd-build");

var outprop = "amdoutput";
var outdir = "./build/";
var tmpdir = "./tmp/";

grunt.initConfig({
amdloader: {
baseUrl: ".",

paths: {
jquery: "bower_components/jquery",
lie: "bower_components/lie",
"requirejs-dplugins": "../../.."
},

// Unfortunately this is needed for the jquery plugin.
// It's automatically handled by the plugin itself at runtime, but not during builds.
map: {
"*": {
"jquery/src/selector": "jquery/src/selector-native"
}
}
},

amdbuild: {
dir: tmpdir,

// List of layers to build.
layers: [
// Test build for jquery plugin. Should contain main test js file and a few jquery modules.
{
name: "app",
include: [
// Modules and layers listed here, and their dependencies, will be added to the layer.
"src"
]
}
]
},

// Config to allow to concatenate files to generate the layer.
concat: {
options: {
banner: "<%= " + outprop + ".header%>",
sourceMap: true
},
dist: {
src: "<%= " + outprop + ".modules.abs %>",
dest: outdir + "<%= " + outprop + ".layerPath %>"
}
},

copy: {
plugins: {
expand: true,
cwd: tmpdir,
src: "<%= " + outprop + ".plugins.rel %>",
dest: outdir
}
},

clean: {
out: [outdir],
temp: [tmpdir]
}
});

grunt.registerTask("amdbuild", function (amdloader) {
var name = this.name, layers = grunt.config(name).layers;
layers.forEach(function (layer) {
grunt.task.run("amddepsscan:" + layer.name + ":" + name + ":" + amdloader);
grunt.task.run("amdserialize:" + layer.name + ":" + name + ":" + outprop);
grunt.task.run("concat");
grunt.task.run("copy:plugins");
});
});
grunt.registerTask("build", [
"clean:out",
"clean:temp",
"amdbuild:amdloader"
]);
};
28 changes: 28 additions & 0 deletions tests/functional/cssApp/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>CSS plugin build test</title>
<script type="text/javascript" src="bower_components/requirejs/require.js"></script>
</head>
<body>
<h1>CSS plugin build test</h1>
<p id="result">This checks that the CSS plugin built the CSS correctly.</p>
</body>
<script language="JavaScript" type="text/javascript">
var ready = false; // set to true when the test page is ready
require({
baseUrl: "build"
}, [
"app" // first load the layer
], function () {
require(["src"], function () {
// Set global variable to signal that the test page is ready
ready = true;
});
});
</script>
</html>
10 changes: 10 additions & 0 deletions tests/functional/cssApp/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "requirejs-dplugins-css-plugin-test-app",
"version": "0.1.0",
"description": "Test application using css! plugin",
"dependencies": {
"lie": ">=2.8",
"jquery": ">=2.1",
"requirejs": "2.1.x"
}
}
12 changes: 12 additions & 0 deletions tests/functional/cssApp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "requirejs-dplugins-css-plugin-test-app",
"version": "0.1.0",
"description": "Test application using css! plugin",
"devDependencies": {
"clean-css": "3.2.2",
"grunt-amd-build": "0.8.x",
"grunt-contrib-clean": "0.6.x",
"grunt-contrib-concat": "0.5.x",
"grunt-contrib-copy": "0.5.x"
}
}
Binary file added tests/functional/cssApp/resources/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/functional/cssApp/src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Mock application for testing css plugin.
// Simply require the styles/styles.css file.
define(["requirejs-dplugins/css!styles/styles.css"], function () {
return function noop() {};
});
1 change: 1 addition & 0 deletions tests/functional/cssApp/styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "substyles/substyles.css";
6 changes: 6 additions & 0 deletions tests/functional/cssApp/styles/substyles/substyles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#result {
color: red;
border: 1px dashed black;
background: url("../../resources/test.png") -15px -18px no-repeat; /* To test path correction */
padding-left: 6em;
}
31 changes: 31 additions & 0 deletions tests/functional/cssBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
define([
"require",
"intern",
"intern!object",
"intern/chai!assert",
"intern/dojo/node!leadfoot/helpers/pollUntil"
], function (require, intern, registerSuite, assert, pollUntil) {

registerSuite({
name: "css plugin build test",

setup: function () {
return this.remote
.get(require.toUrl("./cssApp/app.html"))
.then(pollUntil("return ready || null;", [],
intern.config.WAIT_TIMEOUT, intern.config.POLL_INTERVAL));
},

"css style application": function () {
this.timeout = intern.config.TEST_TIMEOUT;

return this.remote
.findById("result").getComputedStyle("borderLeftStyle").then(function (style) {
assert.strictEqual(style, "dashed");
}).getComputedStyle("backgroundImage").then(function (style) {
var match = style.match(/(build\/resources\/test\.png)\)?;?$/);
assert.strictEqual(match[1], "build/resources/test.png");
});
}
});
});

0 comments on commit dbdd70c

Please sign in to comment.