Skip to content

Commit 13ec341

Browse files
devversionmmalerba
authored andcommitted
build: remove unused gulp test watch code (#18077)
We can remove the unused code for `gulp test` and `gulp test:static`. The equivalent actions can be performed with Bazel and with the upcoming script that simplifies the testing workflow, there is no need for keeping this code in the codebase. All the concerns that have been mentioned in the old PR (#16904) have been resolved.
1 parent 8ef699d commit 13ec341

File tree

2 files changed

+6
-74
lines changed

2 files changed

+6
-74
lines changed

tools/gulp/packages.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,3 @@ export const cdkExperimentalPackage = new BuildPackage('cdk-experimental', [cdkP
88
export const materialExperimentalPackage = new BuildPackage('material-experimental',
99
[cdkPackage, cdkExperimentalPackage, materialPackage]);
1010
export const momentAdapterPackage = new BuildPackage('material-moment-adapter', [materialPackage]);
11-
12-
/** List of all build packages defined for this project. */
13-
export const allBuildPackages = [
14-
cdkPackage,
15-
materialPackage,
16-
youTubePlayerPackage,
17-
cdkExperimentalPackage,
18-
materialExperimentalPackage,
19-
momentAdapterPackage,
20-
googleMapsPackage,
21-
];

tools/gulp/tasks/unit-test.ts

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import {join} from 'path';
2-
import {task, watch} from 'gulp';
2+
import {task} from 'gulp';
33
import {buildConfig, sequenceTask} from '../../package-tools';
44

5-
// There are no type definitions available for these imports.
6-
const runSequence = require('run-sequence');
7-
8-
// Default Karma options.
9-
const defaultOptions = {
10-
configFile: join(buildConfig.projectDir, 'test/karma.conf.js'),
11-
autoWatch: false,
12-
singleRun: false
13-
};
14-
155
/** Builds everything that is necessary for karma. */
166
task(':test:build', sequenceTask(
177
'clean',
@@ -32,60 +22,13 @@ task('test:single-run', [':test:build'], (done: () => void) => {
3222
// Load karma not outside. Karma pollutes Promise with a different implementation.
3323
const karma = require('karma');
3424

35-
new karma.Server({...defaultOptions, singleRun: true}, (exitCode: number) => {
25+
new karma.Server({
26+
configFile: join(buildConfig.projectDir, 'test/karma.conf.js'),
27+
autoWatch: false,
28+
singleRun: true
29+
}, (exitCode: number) => {
3630
// Immediately exit the process if Karma reported errors, because due to
3731
// potential still running tunnel-browsers gulp won't exit properly.
3832
exitCode === 0 ? done() : process.exit(exitCode);
3933
}).start();
4034
});
41-
42-
/**
43-
* [Watch task] Runs the unit tests, rebuilding and re-testing when sources change.
44-
* Does not inline resources.
45-
*
46-
* This task should be used when running unit tests locally.
47-
*/
48-
task('test', [':test:build'], karmaWatchTask());
49-
50-
/**
51-
* Runs a Karma server which will run the unit tests against any browser that connects to it.
52-
* This is identical to `gulp test`, however it won't launch and manage Chrome automatically,
53-
* which makes it convenient debugging unit tests against multiple different browsers.
54-
*/
55-
task('test:static', [':test:build'], karmaWatchTask({browsers: []}));
56-
57-
/**
58-
* Returns a Gulp task that spawns a Karma server and reloads whenever the files change.
59-
* Note that this doesn't use Karma's built-in file watching. Due to the way our build
60-
* process is set up, Karma ends up firing its change detection for every file that is
61-
* written to disk, which causes it to run tests multiple time and makes it hard to follow
62-
* the console output. This approach runs the Karma server and then depends on the Gulp API
63-
* to tell Karma when to run the tests.
64-
* @param options Karma options to use on top of the defaults.
65-
*/
66-
function karmaWatchTask(options?: any) {
67-
return () => {
68-
const patternRoot = join(buildConfig.packagesDir, '**/*');
69-
// Note: Karma shouldn't be required from the outside, because it
70-
// pollutes the global Promise with a custom implementation.
71-
const karma = require('karma');
72-
73-
// Configure the Karma server and override the autoWatch and singleRun just in case.
74-
const server = new karma.Server({...defaultOptions, ...options});
75-
76-
// Refreshes Karma's file list and schedules a test run.
77-
// Tests will only run if TypeScript compilation was successful.
78-
const runTests = (error?: Error) => {
79-
if (!error) {
80-
server.refreshFiles().then(() => server._injector.get('executor').schedule());
81-
}
82-
};
83-
84-
// Boot up the test server and run the tests whenever a new browser connects.
85-
server.start();
86-
server.on('browser_register', () => runTests());
87-
88-
// Whenever a file change has been recognized, rebuild and re-run the tests.
89-
watch(patternRoot + '.+(ts|scss|html)', () => runSequence(':test:build', runTests));
90-
};
91-
}

0 commit comments

Comments
 (0)