-
Notifications
You must be signed in to change notification settings - Fork 0
/
jasmine-karma-quickstart.txt
196 lines (131 loc) · 4.84 KB
/
jasmine-karma-quickstart.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
1. Add more dev tools like jquery:
$ npm install jquery --save
src/main.js
---------
import $ from 'jquery';
Or like bootstrap:
$ npm install popper.js --save
$ npm install bootstrap --save
src/main.js
----------
import 'bootstrap';
2. Install Jasmine's core module:
$ npm install jasmine-core@2.99.0 --save-dev
helper command:
$ npm install jasmine@3.1.0 --save-dev
3. Initialize Jasmine:
$ ./node_modules/.bin/jasmine init
4. Update your package.json to include a command to run jasmine:
package.json
----------
"scripts": {
"build": "webpack",
"test": "jasmine"
### Remember to add a comma between these commands!!! Otherwise
your whole thing could break!!!
5. Install Karma, which is a separate package that runs the tests
that you write for Jasmine!
$ npm install karma@2.0.0 --save-dev
$ npm install karma-jasmine@1.1.1 --save-dev
This installs the chrome spec viewer:
$ npm install karma-chrome-launcher@2.2.0 --save-dev
This installs global karma commands:
$ npm install karma-cli@1.0.1 -g
This installs your copy of Karma for the webpack!
$ npm install karma-cli@1.0.1 --save-dev
This makes Karma not freak out about Jquery!
$ npm install karma-jquery@0.2.2 --save-dev
This makes Karma look nice in the window!
$ npm install karma-jasmine-html-reporter@0.2.2 --save-dev
This runs webpack, but lets Karma automatically use source mapping.
$ npm install karma-sourcemap-loader@0.3.7 --save-dev
6. Congrats! You have good Karma! Now run it!
$ karma init
7. Edit your newly created karma.conf.js file. The layout is nice and we
can still use it, just pasting in specific parts. This is
a slightly more readable format, including those comments:
COPY BELOW
******************************************
// Karma configuration
// Generated on Wed Jun 26 2019 09:18:52 GMT-0700 (PDT)
const webpackConfig = require('./webpack.config.js');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jquery-3.2.1','jasmine'],
// list of files / patterns to load in the browser
files: [
'src/*.js',
'spec/*spec.js'
],
webpack: webpackConfig,
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/*.js': ['webpack', 'sourcemap'],
'spec/*spec.js': ['webpack', 'sourcemap']
},
plugins: [
'karma-jquery',
'karma-webpack',
'karma-jasmine',
'karma-chrome-launcher',
'karma-jasmine-html-reporter',
'karma-sourcemap-loader'
],
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'kjhtml'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
******************************************
COPY ABOVE
8. Change your "test" command in package.json to the new Karma command:
"scripts": {
"build": "webpack",
"test": "./node_modules/karma/bin/karma start karma.conf.js"
},
9. Exclude specs from ESLint, so that your thing still builds.
### QUICK NOTE! I didn't use ES Lint in any of my stuff because it's a bit of a mystery
to me, and keeps breaking my builds. If anyone has a solution,
I'd love to look at it!!
webpack.config.js
-----------------
module.exports = {
...
{
test: /\.js$/,
exclude: [
/node_modules/,
/spec/
],
loader: "eslint-loader"
}
]
}
};