Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6b1e4ad5
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6b1e4ad5
编写于
5月 01, 2018
作者:
M
Mike Greiling
提交者:
Clement Ho
5月 01, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix memory and performance issues in Karma test suite
上级
71d53ebc
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
280 addition
and
452 deletion
+280
-452
config/karma.config.js
config/karma.config.js
+61
-16
config/webpack.config.js
config/webpack.config.js
+3
-0
doc/development/testing_guide/frontend_testing.md
doc/development/testing_guide/frontend_testing.md
+41
-33
package.json
package.json
+5
-4
spec/javascripts/test_bundle.js
spec/javascripts/test_bundle.js
+1
-11
yarn.lock
yarn.lock
+169
-388
未找到文件。
config/karma.config.js
浏览文件 @
6b1e4ad5
var
path
=
require
(
'
path
'
);
const
path
=
require
(
'
path
'
);
var
webpack
=
require
(
'
webpack
'
);
const
glob
=
require
(
'
glob
'
);
var
argumentsParser
=
require
(
'
commander
'
);
const
chalk
=
require
(
'
chalk
'
);
var
webpackConfig
=
require
(
'
./webpack.config.js
'
);
const
webpack
=
require
(
'
webpack
'
);
var
ROOT_PATH
=
path
.
resolve
(
__dirname
,
'
..
'
);
const
argumentsParser
=
require
(
'
commander
'
);
const
webpackConfig
=
require
(
'
./webpack.config.js
'
);
const
ROOT_PATH
=
path
.
resolve
(
__dirname
,
'
..
'
);
function
fatalError
(
message
)
{
console
.
error
(
chalk
.
red
(
`\nError:
${
message
}
\n`
));
process
.
exit
(
1
);
}
// remove problematic plugins
// remove problematic plugins
if
(
webpackConfig
.
plugins
)
{
if
(
webpackConfig
.
plugins
)
{
...
@@ -15,33 +23,70 @@ if (webpackConfig.plugins) {
...
@@ -15,33 +23,70 @@ if (webpackConfig.plugins) {
});
});
}
}
var
testFile
s
=
argumentsParser
const
specFilter
s
=
argumentsParser
.
option
(
.
option
(
'
-f, --filter-spec [filter]
'
,
'
-f, --filter-spec [filter]
'
,
'
Filter run spec files by path. Multiple filters are like a logical OR.
'
,
'
Filter run spec files by path. Multiple filters are like a logical OR.
'
,
(
val
,
memo
)
=>
{
(
filter
,
memo
)
=>
{
memo
.
push
(
val
);
memo
.
push
(
filter
,
filter
.
replace
(
/
\/?
$/
,
'
/**/*.js
'
)
);
return
memo
;
return
memo
;
},
},
[]
[]
)
)
.
parse
(
process
.
argv
).
filterSpec
;
.
parse
(
process
.
argv
).
filterSpec
;
webpackConfig
.
plugins
.
push
(
if
(
specFilters
.
length
)
{
new
webpack
.
DefinePlugin
({
const
specsPath
=
/^
(?:\.[\\\/])?
spec
[\\\/]
javascripts
[\\\/]
/
;
'
process.env.TEST_FILES
'
:
JSON
.
stringify
(
testFiles
),
})
// resolve filters
);
let
filteredSpecFiles
=
specFilters
.
map
(
filter
=>
glob
.
sync
(
filter
,
{
root
:
ROOT_PATH
,
matchBase
:
true
,
})
.
filter
(
path
=>
path
.
endsWith
(
'
spec.js
'
))
);
// flatten
filteredSpecFiles
=
Array
.
prototype
.
concat
.
apply
([],
filteredSpecFiles
);
// remove duplicates
filteredSpecFiles
=
[...
new
Set
(
filteredSpecFiles
)];
if
(
filteredSpecFiles
.
length
<
1
)
{
fatalError
(
'
Your filter did not match any test files.
'
);
}
if
(
!
filteredSpecFiles
.
every
(
file
=>
specsPath
.
test
(
file
)))
{
fatalError
(
'
Test files must be located within /spec/javascripts.
'
);
}
const
newContext
=
filteredSpecFiles
.
reduce
((
context
,
file
)
=>
{
const
relativePath
=
file
.
replace
(
specsPath
,
''
);
context
[
file
]
=
`./
${
relativePath
}
`
;
return
context
;
},
{});
webpackConfig
.
plugins
.
push
(
new
webpack
.
ContextReplacementPlugin
(
/spec
[\\\/]
javascripts$/
,
path
.
join
(
ROOT_PATH
,
'
spec/javascripts
'
),
newContext
)
);
}
webpackConfig
.
devtool
=
process
.
env
.
BABEL_ENV
!==
'
coverage
'
&&
'
cheap-inline-source-map
'
;
webpackConfig
.
entry
=
undefined
;
webpackConfig
.
devtool
=
'
cheap-inline-source-map
'
;
// Karma configuration
// Karma configuration
module
.
exports
=
function
(
config
)
{
module
.
exports
=
function
(
config
)
{
process
.
env
.
TZ
=
'
Etc/UTC
'
;
process
.
env
.
TZ
=
'
Etc/UTC
'
;
var
progressReporter
=
process
.
env
.
CI
?
'
mocha
'
:
'
progress
'
;
const
progressReporter
=
process
.
env
.
CI
?
'
mocha
'
:
'
progress
'
;
var
karmaConfig
=
{
const
karmaConfig
=
{
basePath
:
ROOT_PATH
,
basePath
:
ROOT_PATH
,
browsers
:
[
'
ChromeHeadlessCustom
'
],
browsers
:
[
'
ChromeHeadlessCustom
'
],
customLaunchers
:
{
customLaunchers
:
{
...
...
config/webpack.config.js
浏览文件 @
6b1e4ad5
...
@@ -69,6 +69,9 @@ const config = {
...
@@ -69,6 +69,9 @@ const config = {
test
:
/
\.
js$/
,
test
:
/
\.
js$/
,
exclude
:
/
(
node_modules|vendor
\/
assets
)
/
,
exclude
:
/
(
node_modules|vendor
\/
assets
)
/
,
loader
:
'
babel-loader
'
,
loader
:
'
babel-loader
'
,
options
:
{
cacheDirectory
:
path
.
join
(
ROOT_PATH
,
'
tmp/cache/babel-loader
'
),
},
},
},
{
{
test
:
/
\.
vue$/
,
test
:
/
\.
vue$/
,
...
...
doc/development/testing_guide/frontend_testing.md
浏览文件 @
6b1e4ad5
...
@@ -62,6 +62,7 @@ describe('.methodName', () => {
...
@@ -62,6 +62,7 @@ describe('.methodName', () => {
});
});
});
});
```
```
#### Testing promises
#### Testing promises
When testing Promises you should always make sure that the test is asynchronous and rejections are handled.
When testing Promises you should always make sure that the test is asynchronous and rejections are handled.
...
@@ -69,9 +70,9 @@ Your Promise chain should therefore end with a call of the `done` callback and `
...
@@ -69,9 +70,9 @@ Your Promise chain should therefore end with a call of the `done` callback and `
```
javascript
```
javascript
// Good
// Good
it
(
'
tests a promise
'
,
(
done
)
=>
{
it
(
'
tests a promise
'
,
done
=>
{
promise
promise
.
then
(
(
data
)
=>
{
.
then
(
data
=>
{
expect
(
data
).
toBe
(
asExpected
);
expect
(
data
).
toBe
(
asExpected
);
})
})
.
then
(
done
)
.
then
(
done
)
...
@@ -79,10 +80,10 @@ it('tests a promise', (done) => {
...
@@ -79,10 +80,10 @@ it('tests a promise', (done) => {
});
});
// Good
// Good
it
(
'
tests a promise rejection
'
,
(
done
)
=>
{
it
(
'
tests a promise rejection
'
,
done
=>
{
promise
promise
.
then
(
done
.
fail
)
.
then
(
done
.
fail
)
.
catch
(
(
error
)
=>
{
.
catch
(
error
=>
{
expect
(
error
).
toBe
(
expectedError
);
expect
(
error
).
toBe
(
expectedError
);
})
})
.
then
(
done
)
.
then
(
done
)
...
@@ -91,38 +92,37 @@ it('tests a promise rejection', (done) => {
...
@@ -91,38 +92,37 @@ it('tests a promise rejection', (done) => {
// Bad (missing done callback)
// Bad (missing done callback)
it
(
'
tests a promise
'
,
()
=>
{
it
(
'
tests a promise
'
,
()
=>
{
promise
promise
.
then
(
data
=>
{
.
then
((
data
)
=>
{
expect
(
data
).
toBe
(
asExpected
);
expect
(
data
).
toBe
(
asExpected
);
});
})
});
});
// Bad (missing catch)
// Bad (missing catch)
it
(
'
tests a promise
'
,
(
done
)
=>
{
it
(
'
tests a promise
'
,
done
=>
{
promise
promise
.
then
(
(
data
)
=>
{
.
then
(
data
=>
{
expect
(
data
).
toBe
(
asExpected
);
expect
(
data
).
toBe
(
asExpected
);
})
})
.
then
(
done
)
.
then
(
done
)
;
});
});
// Bad (use done.fail in asynchronous tests)
// Bad (use done.fail in asynchronous tests)
it
(
'
tests a promise
'
,
(
done
)
=>
{
it
(
'
tests a promise
'
,
done
=>
{
promise
promise
.
then
(
(
data
)
=>
{
.
then
(
data
=>
{
expect
(
data
).
toBe
(
asExpected
);
expect
(
data
).
toBe
(
asExpected
);
})
})
.
then
(
done
)
.
then
(
done
)
.
catch
(
fail
)
.
catch
(
fail
)
;
});
});
// Bad (missing catch)
// Bad (missing catch)
it
(
'
tests a promise rejection
'
,
(
done
)
=>
{
it
(
'
tests a promise rejection
'
,
done
=>
{
promise
promise
.
catch
(
(
error
)
=>
{
.
catch
(
error
=>
{
expect
(
error
).
toBe
(
expectedError
);
expect
(
error
).
toBe
(
expectedError
);
})
})
.
then
(
done
)
.
then
(
done
)
;
});
});
```
```
...
@@ -139,7 +139,7 @@ documentation for these methods can be found in the [jasmine introduction page](
...
@@ -139,7 +139,7 @@ documentation for these methods can be found in the [jasmine introduction page](
Sometimes you may need to spy on a method that is directly imported by another
Sometimes you may need to spy on a method that is directly imported by another
module. GitLab has a custom
`spyOnDependency`
method which utilizes
module. GitLab has a custom
`spyOnDependency`
method which utilizes
[
babel-plugin-rewire
](
https://github.com/speedskater/babel-plugin-rewire
)
to
[
babel-plugin-rewire
](
https://github.com/speedskater/babel-plugin-rewire
)
to
achieve this.
It can be used like so:
achieve this. It can be used like so:
```
javascript
```
javascript
// my_module.js
// my_module.js
...
@@ -181,8 +181,8 @@ See this [section][vue-test].
...
@@ -181,8 +181,8 @@ See this [section][vue-test].
`rake karma`
runs the frontend-only (JavaScript) tests.
`rake karma`
runs the frontend-only (JavaScript) tests.
It consists of two subtasks:
It consists of two subtasks:
-
`rake karma:fixtures`
(re-)generates fixtures
*
`rake karma:fixtures`
(re-)generates fixtures
-
`rake karma:tests`
actually executes the tests
*
`rake karma:tests`
actually executes the tests
As long as the fixtures don't change,
`rake karma:tests`
(or
`yarn karma`
)
As long as the fixtures don't change,
`rake karma:tests`
(or
`yarn karma`
)
is sufficient (and saves you some time).
is sufficient (and saves you some time).
...
@@ -217,6 +217,14 @@ yarn karma-start --filter-spec profile/account/components/
...
@@ -217,6 +217,14 @@ yarn karma-start --filter-spec profile/account/components/
yarn karma-start
-f
vue_shared
-f
vue_mr_widget
yarn karma-start
-f
vue_shared
-f
vue_mr_widget
```
```
You can also use glob syntax to match files. Remember to put quotes around the
glob otherwise your shell may split it into multiple arguments:
```
bash
# Run all specs named `file_spec` within the IDE subdirectory
yarn karma
-f
'spec/javascripts/ide/**/file_spec.js'
```
## RSpec feature integration tests
## RSpec feature integration tests
Information on setting up and running RSpec integration tests with
Information on setting up and running RSpec integration tests with
...
@@ -231,14 +239,14 @@ supported by the PhantomJS test runner which is used for both Karma and RSpec
...
@@ -231,14 +239,14 @@ supported by the PhantomJS test runner which is used for both Karma and RSpec
tests. We polyfill some JavaScript objects for older browsers, but some
tests. We polyfill some JavaScript objects for older browsers, but some
features are still unavailable:
features are still unavailable:
-
Array.from
*
Array.from
-
Array.first
*
Array.first
-
Async functions
*
Async functions
-
Generators
*
Generators
-
Array destructuring
*
Array destructuring
-
For..Of
*
For..Of
-
Symbol/Symbol.iterator
*
Symbol/Symbol.iterator
-
Spread
*
Spread
Until these are polyfilled appropriately, they should not be used. Please
Until these are polyfilled appropriately, they should not be used. Please
update this list with additional unsupported features.
update this list with additional unsupported features.
...
@@ -295,11 +303,11 @@ Scenario: Developer can approve merge request
...
@@ -295,11 +303,11 @@ Scenario: Developer can approve merge request
[
jasmine-focus
]:
https://jasmine.github.io/2.5/focused_specs.html
[
jasmine-focus
]:
https://jasmine.github.io/2.5/focused_specs.html
[
jasmine-jquery
]:
https://github.com/velesin/jasmine-jquery
[
jasmine-jquery
]:
https://github.com/velesin/jasmine-jquery
[
karma
]:
http://karma-runner.github.io/
[
karma
]:
http://karma-runner.github.io/
[
vue-test
]:
https://docs.gitlab.com/ce/development/fe_guide/vue.html#testing-vue-components
[
vue-test
]:
https://docs.gitlab.com/ce/development/fe_guide/vue.html#testing-vue-components
[
RS
pec
]:
https://github.com/rspec/rspec-rails#feature-specs
[
rs
pec
]:
https://github.com/rspec/rspec-rails#feature-specs
[
C
apybara
]:
https://github.com/teamcapybara/capybara
[
c
apybara
]:
https://github.com/teamcapybara/capybara
[
K
arma
]:
http://karma-runner.github.io/
[
k
arma
]:
http://karma-runner.github.io/
[
J
asmine
]:
https://jasmine.github.io/
[
j
asmine
]:
https://jasmine.github.io/
---
---
...
...
package.json
浏览文件 @
6b1e4ad5
...
@@ -98,10 +98,11 @@
...
@@ -98,10 +98,11 @@
"devDependencies"
:
{
"devDependencies"
:
{
"
axios-mock-adapter
"
:
"
^1.10.0
"
,
"
axios-mock-adapter
"
:
"
^1.10.0
"
,
"
babel-eslint
"
:
"
^8.0.2
"
,
"
babel-eslint
"
:
"
^8.0.2
"
,
"
babel-plugin-istanbul
"
:
"
^4.1.
5
"
,
"
babel-plugin-istanbul
"
:
"
^4.1.
6
"
,
"
babel-plugin-rewire
"
:
"
^1.1.0
"
,
"
babel-plugin-rewire
"
:
"
^1.1.0
"
,
"
babel-template
"
:
"
^6.26.0
"
,
"
babel-template
"
:
"
^6.26.0
"
,
"
babel-types
"
:
"
^6.26.0
"
,
"
babel-types
"
:
"
^6.26.0
"
,
"
chalk
"
:
"
^2.4.1
"
,
"
commander
"
:
"
^2.15.1
"
,
"
commander
"
:
"
^2.15.1
"
,
"
eslint
"
:
"
^3.18.0
"
,
"
eslint
"
:
"
^3.18.0
"
,
"
eslint-config-airbnb-base
"
:
"
^10.0.1
"
,
"
eslint-config-airbnb-base
"
:
"
^10.0.1
"
,
...
@@ -116,13 +117,13 @@
...
@@ -116,13 +117,13 @@
"
istanbul
"
:
"
^0.4.5
"
,
"
istanbul
"
:
"
^0.4.5
"
,
"
jasmine-core
"
:
"
^2.9.0
"
,
"
jasmine-core
"
:
"
^2.9.0
"
,
"
jasmine-jquery
"
:
"
^2.1.1
"
,
"
jasmine-jquery
"
:
"
^2.1.1
"
,
"
karma
"
:
"
^2.0.
0
"
,
"
karma
"
:
"
^2.0.
2
"
,
"
karma-chrome-launcher
"
:
"
^2.2.0
"
,
"
karma-chrome-launcher
"
:
"
^2.2.0
"
,
"
karma-coverage-istanbul-reporter
"
:
"
^1.4.
1
"
,
"
karma-coverage-istanbul-reporter
"
:
"
^1.4.
2
"
,
"
karma-jasmine
"
:
"
^1.1.1
"
,
"
karma-jasmine
"
:
"
^1.1.1
"
,
"
karma-mocha-reporter
"
:
"
^2.2.5
"
,
"
karma-mocha-reporter
"
:
"
^2.2.5
"
,
"
karma-sourcemap-loader
"
:
"
^0.3.7
"
,
"
karma-sourcemap-loader
"
:
"
^0.3.7
"
,
"
karma-webpack
"
:
"
2.0.7
"
,
"
karma-webpack
"
:
"
3.0.0
"
,
"
nodemon
"
:
"
^1.15.1
"
,
"
nodemon
"
:
"
^1.15.1
"
,
"
prettier
"
:
"
1.11.1
"
,
"
prettier
"
:
"
1.11.1
"
,
"
webpack-dev-server
"
:
"
^2.11.2
"
"
webpack-dev-server
"
:
"
^2.11.2
"
...
...
spec/javascripts/test_bundle.js
浏览文件 @
6b1e4ad5
...
@@ -84,21 +84,11 @@ beforeEach(() => {
...
@@ -84,21 +84,11 @@ beforeEach(() => {
const
axiosDefaultAdapter
=
getDefaultAdapter
();
const
axiosDefaultAdapter
=
getDefaultAdapter
();
let
testFiles
=
process
.
env
.
TEST_FILES
||
[];
if
(
testFiles
.
length
>
0
)
{
testFiles
=
testFiles
.
map
(
path
=>
path
.
replace
(
/^spec
\/
javascripts
\/
/
,
''
).
replace
(
/
\.
js$/
,
''
));
console
.
log
(
`Running only tests matching:
${
testFiles
}
`
);
}
else
{
console
.
log
(
'
Running all tests
'
);
}
// render all of our tests
// render all of our tests
const
testsContext
=
require
.
context
(
'
.
'
,
true
,
/_spec$/
);
const
testsContext
=
require
.
context
(
'
.
'
,
true
,
/_spec$/
);
testsContext
.
keys
().
forEach
(
function
(
path
)
{
testsContext
.
keys
().
forEach
(
function
(
path
)
{
try
{
try
{
if
(
testFiles
.
length
===
0
||
testFiles
.
some
(
p
=>
path
.
includes
(
p
)))
{
testsContext
(
path
);
testsContext
(
path
);
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
[ERROR] Unable to load spec:
'
,
path
);
console
.
error
(
'
[ERROR] Unable to load spec:
'
,
path
);
describe
(
'
Test bundle
'
,
function
()
{
describe
(
'
Test bundle
'
,
function
()
{
...
...
yarn.lock
浏览文件 @
6b1e4ad5
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录