Situation : I am currently using QUnit to test a project in TypeScript/Javascript and everything works fine when I'm running them in a browser.
Problem : I'm trying to use grunt to run the QUnit tests in a headless mode (I need it for continuous integration testing) and the tests don't run properly.
Configuration Here's how I have things currently set up :
Gruntfile.js
package.json
src/
- Ts source files
test/
- config.js
- Test.ts
- Test.js
- test.html
Gruntfile.js
/*global module:false*/
module.exports = function(grunt) {
grunt.initConfig({
connect: {
server: {
options: {
port: 8000,
base: '.'
}
}
},
qunit: {
all: {
options: {
urls: [
'http://localhost:8000/test/test.html'
]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('test', ['connect', 'qunit']);
};
package.json
{
// Name, version, description, repo and author fields...
"engines": {
"node": ">= 0.10.0"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-connect": "~0.9.0",
"grunt-contrib-qunit": "~0.5.2"
}
}
And then I have a .travis.yml file to run all of this. I don't know if it's really important because the tests don't run either in travis or in my local environment, but here is it anyways :
language: node_js
node_js:
- "0.11"
- "0.10"
before_install:
- "npm install grunt --save-dev"
- "npm install -g grunt-cli"
install:
- "npm install"
- "npm install -g typescript"
script:
- "tsc --module amd --target ES5 ./src/*.ts"
- "grunt test --verbose --force"
And here's the part that errors in the travis build : http://puu.sh/eKpWj/35614680e1.png
(I currently have ~20 assertions that pass when I'm running them in a browser. Also, the typescript compilation runs ok.)
Edit : And as someone asked fot it, here's the content of the Test.html file : http://pastebin.com/LN3igmjc
Edit 2 : Here's also the content of config.js :
var require = {
baseUrl: "../src/"
};
Actually I managed to make it work. I changed two things :
tsc --module amd --target ES5 ./src/*.ts
compiled the files in the src
folder, and the test files were in the test
folder. I'm bashing myself for this one... So I simply added tsc --module amd --target ES5 ./test/*.ts
in the .travis.yml
file QUnit.config.autostart = false;
and make them start when I want with QUnit.start();
I placed this start() at the end of my Test.js
file so that the tests start only when QUnit is done loading.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.