UNPKG

5.23 kBJavaScriptView Raw
1'use strict';
2
3var Jasmine = require('jasmine');
4
5module.exports = function (grunt) {
6 var jasmineRequireJsOptions = {
7 specs: 'test/*-test.js',
8 helpers: 'test/*-helper.js',
9 };
10
11 // Project configuration.
12 grunt.initConfig({
13 // Metadata.
14 pkg: grunt.file.readJSON('package.json'),
15 banner: '/*! <%= pkg.name %> - v<%= pkg.version %>' +
16 ' - <%= pkg.homepage %>' +
17 ' - (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' +
18 ' - licensed <%= pkg.license %> */\n',
19 // Task configuration.
20 concat: {
21 options: {
22 banner: '<%= banner %>',
23 stripBanners: true
24 },
25 dist: {
26 src: ['lib/<%= pkg.name %>.js'],
27 dest: 'dist/<%= pkg.name %>.js'
28 }
29 },
30 uglify: {
31 options: {
32 banner: '<%= banner %>'
33 },
34 dist: {
35 src: '<%= concat.dist.dest %>',
36 dest: 'dist/<%= pkg.name %>.min.js'
37 }
38 },
39 jasmine: {
40 requirejs: {
41 src: [],
42 options: {
43 specs: jasmineRequireJsOptions.specs,
44 helpers: jasmineRequireJsOptions.helpers,
45 template: require('./vendor/grunt-template-jasmine-requirejs')
46 }
47 },
48 global: {
49 src: 'lib/**/*.js',
50 options: {
51 specs: 'test/global-integration.js',
52 }
53 },
54 context: {
55 src: 'test/test-context-using-apply.generated.js',
56 options: {
57 specs: 'test/global-integration-with-new-context.js',
58 }
59 }
60 },
61 jasmine_node: {
62 options: {
63 specs: ['test/node-integration.js']
64 }
65 },
66 open: {
67 jasmine: {
68 path: 'http://127.0.0.1:8000/_SpecRunner.html'
69 }
70 },
71 connect: {
72 test: {
73 port: 8000,
74 keepalive: true
75 }
76 },
77 jshint: {
78 options: {
79 jshintrc: '.jshintrc'
80 },
81 gruntfile: {
82 src: 'Gruntfile.js'
83 },
84 lib: {
85 options: {
86 jshintrc: 'lib/.jshintrc'
87 },
88 src: ['lib/**/*.js']
89 },
90 test: {
91 options: {
92 jshintrc: 'test/.jshintrc'
93 },
94 src: ['test/*.js', '!test/*.generated.js']
95 }
96 },
97 watch: {
98 gruntfile: {
99 files: '<%= jshint.gruntfile.src %>',
100 tasks: ['jshint:gruntfile']
101 },
102 lib: {
103 files: '<%= jshint.lib.src %>',
104 tasks: ['jshint:lib', 'test']
105 },
106 test: {
107 files: '<%= jshint.test.src %>',
108 tasks: ['jshint:test', 'test']
109 }
110 },
111 preprocess: {
112 "test-context-using-apply": {
113 src: 'test/test-context-using-apply.js',
114 dest: 'test/test-context-using-apply.generated.js'
115 }
116 },
117 clean:{
118 test:['test/test-context-using-apply.generated.js']
119 }
120 });
121
122 // These plugins provide necessary tasks.
123 grunt.loadNpmTasks('grunt-contrib-concat');
124 grunt.loadNpmTasks('grunt-contrib-uglify');
125 grunt.loadNpmTasks('grunt-contrib-jasmine');
126 grunt.loadNpmTasks('grunt-contrib-jshint');
127 grunt.loadNpmTasks('grunt-contrib-watch');
128
129 grunt.loadNpmTasks('grunt-contrib-connect');
130 grunt.loadNpmTasks('grunt-open');
131 grunt.loadNpmTasks('grunt-preprocess');
132 grunt.loadNpmTasks('grunt-contrib-clean');
133
134 // Run Jasmine with Node.js tests (as opposed to browser tests).
135 //
136 // NOTE: This is designed for Jasmine 2.4, which matches the version used
137 // in `grunt-contrib-jasmine`. If that package is updated, this should also
138 // be updated to match.
139 grunt.registerTask('jasmine_node', 'Run Jasmine in Node.js', function() {
140 var done = this.async();
141
142 var jasmine = new Jasmine({ projectBaseDir: __dirname });
143 jasmine.onComplete(function(success) {
144 done(success);
145 });
146
147 jasmine.execute(this.options().specs);
148 });
149
150 // Build a distributable release
151 grunt.registerTask('dist', ['test', 'dist-build']);
152 grunt.registerTask('dist-build', ['concat', 'uglify']);
153
154 // Check everything is good
155 grunt.registerTask('test', ['jshint', 'test-browser', 'test-node']);
156 grunt.registerTask('test-browser', ['jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine:requirejs']);
157 grunt.registerTask('test-node', ['jasmine_node']);
158
159 // Test with a live server and an actual browser
160 grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);
161
162 // Default task.
163 grunt.registerTask('default', 'test');
164};