Skip to content

Commit dbdd70c

Browse files
committed
add build test for css plugin. refs #6
1 parent 7f11fc2 commit dbdd70c

File tree

12 files changed

+191
-3
lines changed

12 files changed

+191
-3
lines changed

Gruntfile.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ module.exports = function (grunt) {
8484
// Travis build
8585
grunt.registerTask("travis", ["jshint", "test:remote"]);
8686

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

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

9292
function npmInstall(error, bowerResults) {
9393
if (error !== null) {
@@ -168,7 +168,8 @@ module.exports = function (grunt) {
168168
}
169169

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

173174
// Then run the intern tests.
174175
grunt.task.run("intern:" + target);

tests/functional/all.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Listing of all the plugin functional tests
22
define([
3+
"./cssBuild",
34
"./jqueryBuild",
45
"./jqueryScript"
56
]);

tests/functional/cssApp/.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "bower_components"
3+
}

tests/functional/cssApp/Gruntfile.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Gruntfile for building layer including src.js and the jquery modules it references
2+
module.exports = function (grunt) {
3+
"use strict";
4+
5+
grunt.loadNpmTasks("grunt-contrib-clean");
6+
grunt.loadNpmTasks("grunt-contrib-copy");
7+
grunt.loadNpmTasks("grunt-contrib-concat");
8+
grunt.loadNpmTasks("grunt-amd-build");
9+
10+
var outprop = "amdoutput";
11+
var outdir = "./build/";
12+
var tmpdir = "./tmp/";
13+
14+
grunt.initConfig({
15+
amdloader: {
16+
baseUrl: ".",
17+
18+
paths: {
19+
jquery: "bower_components/jquery",
20+
lie: "bower_components/lie",
21+
"requirejs-dplugins": "../../.."
22+
},
23+
24+
// Unfortunately this is needed for the jquery plugin.
25+
// It's automatically handled by the plugin itself at runtime, but not during builds.
26+
map: {
27+
"*": {
28+
"jquery/src/selector": "jquery/src/selector-native"
29+
}
30+
}
31+
},
32+
33+
amdbuild: {
34+
dir: tmpdir,
35+
36+
// List of layers to build.
37+
layers: [
38+
// Test build for jquery plugin. Should contain main test js file and a few jquery modules.
39+
{
40+
name: "app",
41+
include: [
42+
// Modules and layers listed here, and their dependencies, will be added to the layer.
43+
"src"
44+
]
45+
}
46+
]
47+
},
48+
49+
// Config to allow to concatenate files to generate the layer.
50+
concat: {
51+
options: {
52+
banner: "<%= " + outprop + ".header%>",
53+
sourceMap: true
54+
},
55+
dist: {
56+
src: "<%= " + outprop + ".modules.abs %>",
57+
dest: outdir + "<%= " + outprop + ".layerPath %>"
58+
}
59+
},
60+
61+
copy: {
62+
plugins: {
63+
expand: true,
64+
cwd: tmpdir,
65+
src: "<%= " + outprop + ".plugins.rel %>",
66+
dest: outdir
67+
}
68+
},
69+
70+
clean: {
71+
out: [outdir],
72+
temp: [tmpdir]
73+
}
74+
});
75+
76+
grunt.registerTask("amdbuild", function (amdloader) {
77+
var name = this.name, layers = grunt.config(name).layers;
78+
layers.forEach(function (layer) {
79+
grunt.task.run("amddepsscan:" + layer.name + ":" + name + ":" + amdloader);
80+
grunt.task.run("amdserialize:" + layer.name + ":" + name + ":" + outprop);
81+
grunt.task.run("concat");
82+
grunt.task.run("copy:plugins");
83+
});
84+
});
85+
grunt.registerTask("build", [
86+
"clean:out",
87+
"clean:temp",
88+
"amdbuild:amdloader"
89+
]);
90+
};

tests/functional/cssApp/app.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
5+
<meta name="viewport"
6+
content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
7+
<meta name="apple-mobile-web-app-capable" content="yes"/>
8+
<title>CSS plugin build test</title>
9+
<script type="text/javascript" src="bower_components/requirejs/require.js"></script>
10+
</head>
11+
<body>
12+
<h1>CSS plugin build test</h1>
13+
<p id="result">This checks that the CSS plugin built the CSS correctly.</p>
14+
</body>
15+
<script language="JavaScript" type="text/javascript">
16+
var ready = false; // set to true when the test page is ready
17+
require({
18+
baseUrl: "build"
19+
}, [
20+
"app" // first load the layer
21+
], function () {
22+
require(["src"], function () {
23+
// Set global variable to signal that the test page is ready
24+
ready = true;
25+
});
26+
});
27+
</script>
28+
</html>

tests/functional/cssApp/bower.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "requirejs-dplugins-css-plugin-test-app",
3+
"version": "0.1.0",
4+
"description": "Test application using css! plugin",
5+
"dependencies": {
6+
"lie": ">=2.8",
7+
"jquery": ">=2.1",
8+
"requirejs": "2.1.x"
9+
}
10+
}

tests/functional/cssApp/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "requirejs-dplugins-css-plugin-test-app",
3+
"version": "0.1.0",
4+
"description": "Test application using css! plugin",
5+
"devDependencies": {
6+
"clean-css": "3.2.2",
7+
"grunt-amd-build": "0.8.x",
8+
"grunt-contrib-clean": "0.6.x",
9+
"grunt-contrib-concat": "0.5.x",
10+
"grunt-contrib-copy": "0.5.x"
11+
}
12+
}
609 Bytes
Loading

tests/functional/cssApp/src.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Mock application for testing css plugin.
2+
// Simply require the styles/styles.css file.
3+
define(["requirejs-dplugins/css!styles/styles.css"], function () {
4+
return function noop() {};
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "substyles/substyles.css";

0 commit comments

Comments
 (0)