Skip to content

Commit

Permalink
test: add unit test for lib and an integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and dignifiedquire committed Mar 20, 2018
1 parent 1eb95ee commit 8b45e4f
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ before_script:
script:
- yarn lint
- yarn test
- npm run test:lib
5 changes: 5 additions & 0 deletions examples/simple/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"qunit": true
}
}
28 changes: 28 additions & 0 deletions examples/simple/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function (config) {
config.set({
frameworks: ['qunit'],

files: [
'*'
],

reporters: ['progress'],

port: 9876,

colors: true,

logLevel: config.LOG_INFO,

autoWatch: false,

browsers: ['Chrome'],

singleRun: false,

plugins: [
require('../../lib/index.js'),
'karma-chrome-launcher'
]
})
}
4 changes: 4 additions & 0 deletions examples/simple/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
QUnit.test('it works', function (assert) {
assert.expect(1)
assert.strictEqual(1 + 1, 2)
})
10 changes: 7 additions & 3 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ module.exports = function (grunt) {
},
adapter: {
configFile: 'karma.conf.js'
},
simplequnit: {
configFile: 'examples/simple/karma.conf.js'
}
},
eslint: {
target: [
'src/adapter.js',
'lib/*.js',
'test/*.js',
'lib/index.js',
'test/**/*.js',
'examples/**/*.js',
'gruntfile.js',
'karma.conf.js'
]
Expand All @@ -40,7 +44,7 @@ module.exports = function (grunt) {
require('load-grunt-tasks')(grunt)
grunt.loadTasks('tasks')

grunt.registerTask('test', ['karma'])
grunt.registerTask('test', ['build', 'karma'])
grunt.registerTask('default', ['eslint', 'test'])

grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) {
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function (config) {

files: [
'src/*.js',
'test/*.js'
'test/src/*.js'
],

browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "lib/index.js",
"scripts": {
"lint": "grunt eslint",
"test": "grunt"
"test": "grunt",
"test:lib": "mocha test/lib"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +24,7 @@
"author": "Vojta Jina <vojta.jina@gmail.com>",
"dependencies": {},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.18.2",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.9.0",
Expand All @@ -40,6 +42,7 @@
"karma-firefox-launcher": "1.x || ^0.1.6",
"karma-jasmine": "1.x || ^0.3.6",
"load-grunt-tasks": "^3.2.0",
"mocha": "^5.0.4",
"qunit": "^2.5.1"
},
"peerDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions test/lib/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
30 changes: 30 additions & 0 deletions test/lib/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var initQunit = require('../../lib')['framework:qunit'][1]
var expect = require('chai').expect

describe('framework:qunit', function () {
var files

beforeEach(function () {
files = []
})

it('should add adapter.js', function () {
initQunit(files)

expect(files[1].pattern).to.contain('adapter.js')
})

it('should add qunit.js', function () {
initQunit(files)

expect(files[0].pattern).to.contain('qunit.js')
})

it('should add qunit.css if we define showUI in config', function () {
var qunitConfig = {showUI: true}

initQunit(files, qunitConfig)

expect(files[0].pattern).to.contain('qunit.css')
})
})
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8b45e4f

Please sign in to comment.