Commit 17604d11 authored by Romain Courteaud's avatar Romain Courteaud

Bootstrap automated test environnment.

parent ed7ec9ad
renderjs.js
rsvp.js
node_modules/
npm-debug.log
/*global require */
module.exports = function (grunt) {
"use strict";
var LIVERELOAD_PORT, lrSnippet, livereloadMiddleware;
// This is the default port that livereload listens on;
// change it if you configure livereload to use another port.
LIVERELOAD_PORT = 35729;
// lrSnippet is just a function.
// It's a piece of Connect middleware that injects
// a script into the static served html.
lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
// All the middleware necessary to serve static files.
livereloadMiddleware = function (connect, options) {
return [
// Inject a livereloading script into static files.
lrSnippet,
// Serve static files.
connect.static(options.base),
// Make empty directories browsable.
connect.directory(options.base)
];
};
grunt.loadNpmTasks("grunt-jslint");
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-open');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jslint: {
config: {
src: ['package.json', 'Gruntfile.js'],
directives: {
maxlen: 100,
indent: 2,
maxerr: 3,
predef: [
'module'
]
}
},
test: {
src: ['test/jsonform_test.js'],
directives: {
maxlen: 79,
indent: 2,
maxerr: 3,
unparam: true,
predef: [
'window',
'document',
'QUnit',
'renderJS',
'rJS',
'sinon',
'RSVP'
]
}
},
client: {
src: ['gadget_json_generated_form.js'],
directives: {
maxlen: 79,
indent: 2,
maxerr: 3,
unparam: true,
predef: [
'RSVP',
'window',
'document'
]
}
}
},
copy: {
dependencies: {
files: [{
src: 'node_modules/rsvp/dist/rsvp-2.0.4.js',
dest: "rsvp.js"
}, {
src: 'node_modules/renderjs/dist/renderjs-latest.js',
dest: "renderjs.js"
}]
}
},
watch: {
src: {
files: [
'<%= jslint.client.src %>',
'<%= jslint.config.src %>',
'<%= jslint.test.src %>',
['test/*.html', 'test/*.js']
],
tasks: ['default'],
options: {
livereload: LIVERELOAD_PORT
}
}
},
qunit: {
all: ['test/index.html']
},
connect: {
client: {
options: {
port: 9000,
base: '.',
directory: '.',
middleware: livereloadMiddleware
}
}
},
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= connect.client.options.port%>/test/'
}
}
});
grunt.registerTask('default', ['all']);
grunt.registerTask('all', ['lint']);
grunt.registerTask('lint', ['jslint']);
grunt.registerTask('test', ['copy', 'qunit']);
grunt.registerTask('server', ['connect:client', 'watch']);
};
{
"name": "json_form",
"version": "0.0.1",
"description": "JSON Form validator and editor",
"main": "dist/json-form-latest.js",
"dependencies": {
"rsvp": "git+https://lab.nexedi.com/nexedi/rsvp.js.git",
"renderjs": "git+https://lab.nexedi.com/nexedi/renderjs.git"
},
"devDependencies": {
"connect-livereload": "~0.3.0",
"grunt": "~0.4.1",
"grunt-cli": "~0.1.11",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-qunit": "~0.3.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-jslint": "1.1.14",
"grunt-open": "~0.2.2",
"sinon": "~1.7.3"
},
"scripts": {
"test": "./node_modules/.bin/grunt test",
"lint": "./node_modules/.bin/grunt lint",
"prepublish": "./node_modules/.bin/grunt build"
},
"keywords": [
"jsonform"
],
"author": "Nexedi SA",
"license": "LGPL 3"
}
<!DOCTYPE html>
<html>
<head>
<title>Test JSON form</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../node_modules/grunt-contrib-qunit/test/libs/qunit.css" type="text/css" media="screen"/>
<script src="../rsvp.js" type="text/javascript"></script>
<script src="../renderjs.js" type="text/javascript"></script>
<script src="../node_modules/grunt-contrib-qunit/test/libs/qunit.js" type="text/javascript"></script>
<script src="../node_modules/sinon/pkg/sinon.js" type="text/javascript"></script>
<script src="jsonform_test.js" type="text/javascript"></script>
</head>
<body>
<h1 id="qunit-header">QUnit JSON Form test suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
</body>
</html>
/*jslint nomen: true*/
/*global console*/
(function (document, renderJS, QUnit) {
"use strict";
var test = QUnit.test,
stop = QUnit.stop,
start = QUnit.start,
ok = QUnit.ok,
expect = QUnit.expect,
// equal = QUnit.equal,
// throws = QUnit.throws,
// deepEqual = QUnit.deepEqual,
module = QUnit.module,
// notEqual = QUnit.notEqual,
root_gadget_defer = RSVP.defer(),
jsonform_url = '../gadget_json_generated_form.html';
// Keep track of the root gadget
renderJS(window)
.ready(function () {
root_gadget_defer.resolve(this);
});
/////////////////////////////////////////////////////////////////
// declareGadget
/////////////////////////////////////////////////////////////////
module("jsonform.declareGadget", {
setup: function () {
renderJS.clearGadgetKlassList();
}
});
test('JSON Form gadget can be loaded', function () {
stop();
expect(1);
root_gadget_defer.promise
.then(function (root_gadget) {
return root_gadget.declareGadget(
jsonform_url,
{
sandbox: 'iframe',
element: document.querySelector('#qunit-fixture')
}
);
})
.then(function (gadget) {
ok(true, gadget);
})
.fail(function (error) {
ok(false, error);
console.warn(error);
throw error;
})
.always(function () {
start();
});
});
}(document, renderJS, QUnit));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment