Skip to content

Commit ca9078f

Browse files
OrKoNCommit Bot
authored andcommitted
Move unittests karma config out of the frontend folder
Change-Id: I06e28e5a9afbbf7daa569a9b699c60e4554ed5a9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2395404 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
1 parent 023c3cd commit ca9078f

5 files changed

Lines changed: 45 additions & 26 deletions

File tree

‎scripts/test/run_unittests.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
def run_tests(chrome_binary, target, no_text_coverage, coverage):
2626
cwd = devtools_paths.devtools_root_path()
27-
karmaconfig_path = os.path.join(cwd, 'out', target, 'gen', 'test', 'unittests', 'front_end', 'karma.conf.js')
27+
karmaconfig_path = os.path.join(cwd, 'out', target, 'gen', 'test',
28+
'unittests', 'karma.conf.js')
2829

2930
if not os.path.exists(karmaconfig_path):
3031
print('Unable to find Karma config at ' + karmaconfig_path)
@@ -43,7 +44,6 @@ def run_tests(chrome_binary, target, no_text_coverage, coverage):
4344
env['COVERAGE'] = '1'
4445
if (chrome_binary is not None):
4546
env['CHROME_BIN'] = chrome_binary
46-
4747
exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
4848
if exit_code == 1:
4949
return True

‎test/BUILD.gn‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ group("test") {
77
"e2e",
88
"perf",
99
"shared",
10-
"unittests/front_end",
10+
"unittests",
1111
]
1212
}

‎test/unittests/BUILD.gn‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import("../../scripts/build/ninja/copy.gni")
2+
3+
# Copyright 2020 The Chromium Authors. All rights reserved.
4+
# Use of this source code is governed by a BSD-style license that can be
5+
# found in the LICENSE file.
6+
7+
group("unittests") {
8+
deps = [
9+
":copy_to_gen",
10+
"front_end",
11+
]
12+
}
13+
14+
copy("copy_to_gen") {
15+
sources = [ "karma.conf.js" ]
16+
outputs = [ "$target_gen_dir/karma.conf.js" ]
17+
}

‎test/unittests/front_end/BUILD.gn‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
import("../../../scripts/build/ninja/copy.gni")
6-
75
group("front_end") {
86
deps = [
9-
":copy_karma_conf",
107
"../../../front_end/Images",
118
"bindings",
129
"browser_sdk",
@@ -31,8 +28,3 @@ group("front_end") {
3128
"ui",
3229
]
3330
}
34-
35-
copy("copy_karma_conf") {
36-
sources = [ "karma.conf.js" ]
37-
outputs = [ "$target_gen_dir/karma.conf.js" ]
38-
}
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,40 @@ const COVERAGE_ENABLED = !!process.env['COVERAGE'];
1313
// true by default
1414
const TEXT_COVERAGE_ENABLED = COVERAGE_ENABLED && !process.env['NO_TEXT_COVERAGE'];
1515

16-
const GEN_DIRECTORY = path.join(__dirname, '..', '..', '..');
16+
const GEN_DIRECTORY = path.join(__dirname, '..', '..');
1717
const ROOT_DIRECTORY = path.join(GEN_DIRECTORY, '..', '..', '..');
18-
1918
const browsers = DEBUG_ENABLED ? ['Chrome'] : ['ChromeHeadless'];
2019

2120
const coverageReporters = COVERAGE_ENABLED ? ['coverage'] : [];
2221
const coveragePreprocessors = COVERAGE_ENABLED ? ['coverage'] : [];
2322
const commonIstanbulReporters = [{type: 'html'}, {type: 'json-summary'}];
24-
const istanbulReportOutputs = TEXT_COVERAGE_ENABLED ? [{type: 'text'}, ...commonIstanbulReporters] : commonIstanbulReporters;
23+
const istanbulReportOutputs =
24+
TEXT_COVERAGE_ENABLED ? [{type: 'text'}, ...commonIstanbulReporters] : commonIstanbulReporters;
2525

26-
const UNIT_TESTS_FOLDER = path.join(ROOT_DIRECTORY, 'test', 'unittests', 'front_end');
27-
const TEST_SOURCES = path.join(UNIT_TESTS_FOLDER, '**/*.ts');
26+
const UNIT_TESTS_ROOT_FOLDER = path.join(ROOT_DIRECTORY, 'test', 'unittests');
27+
const UNIT_TESTS_FOLDERS = [
28+
path.join(UNIT_TESTS_ROOT_FOLDER, 'front_end'),
29+
];
30+
const TEST_SOURCES = UNIT_TESTS_FOLDERS.map(folder => path.join(folder, '**/*.ts'));
2831

2932
// To make sure that any leftover JavaScript files (e.g. that were outputs from now-removed tests)
3033
// aren't incorrectly included, we glob for the TypeScript files instead and use that
3134
// to instruct Mocha to run the output JavaScript file.
32-
const TEST_FILES = glob.sync(TEST_SOURCES).map(fileName => {
33-
const jsFile = fileName.replace(/\.ts$/, '.js');
34-
const generatedJsFile = path.join(__dirname, path.relative(UNIT_TESTS_FOLDER, jsFile));
35-
36-
if (!fs.existsSync(generatedJsFile)) {
37-
throw new Error(`Test file ${fileName} is not included in a BUILD.gn and therefore will not be run.`);
38-
}
35+
const TEST_FILES =
36+
TEST_SOURCES
37+
.map(source => {
38+
return glob.sync(source).map(fileName => {
39+
const jsFile = fileName.replace(/\.ts$/, '.js');
40+
const generatedJsFile = path.join(__dirname, path.relative(UNIT_TESTS_ROOT_FOLDER, jsFile));
41+
if (!fs.existsSync(generatedJsFile)) {
42+
throw new Error(`Test file ${fileName} is not included in a BUILD.gn and therefore will not be run.`);
43+
}
44+
45+
return generatedJsFile;
46+
});
47+
})
48+
.flat();
3949

40-
return generatedJsFile;
41-
});
4250

4351
const TEST_FILES_SOURCE_MAPS = TEST_FILES.map(fileName => `${fileName}.map`);
4452

@@ -49,14 +57,16 @@ module.exports = function(config) {
4957
files: [
5058
...TEST_FILES.map(pattern => ({pattern, type: 'module'})),
5159
...TEST_FILES_SOURCE_MAPS.map(pattern => ({pattern, served: true, included: false})),
52-
{pattern: TEST_SOURCES, served: true, included: false},
60+
...TEST_SOURCES.map(source => ({pattern: source, served: true, included: false})),
5361
{pattern: path.join(GEN_DIRECTORY, 'front_end/Images/*.{svg,png}'), served: true, included: false},
5462
{pattern: path.join(GEN_DIRECTORY, 'front_end/**/*.css'), served: true, included: false},
5563
{pattern: path.join(GEN_DIRECTORY, 'front_end/**/*.js'), served: true, included: false},
5664
{pattern: path.join(GEN_DIRECTORY, 'front_end/**/*.js.map'), served: true, included: false},
5765
{pattern: path.join(GEN_DIRECTORY, 'front_end/**/*.mjs'), served: true, included: false},
5866
{pattern: path.join(GEN_DIRECTORY, 'front_end/**/*.mjs.map'), served: true, included: false},
5967
{pattern: path.join(ROOT_DIRECTORY, 'front_end/**/*.ts'), served: true, included: false},
68+
{pattern: path.join(GEN_DIRECTORY, 'inspector_overlay/**/*.js'), served: true, included: false},
69+
{pattern: path.join(GEN_DIRECTORY, 'inspector_overlay/**/*.js.map'), served: true, included: false},
6070
],
6171

6272
reporters: [

0 commit comments

Comments
 (0)