Skip to content

Commit 7cd28ca

Browse files
committed
fix(watch): fix rebuild components on e2e w/ watch
Closes #2642
1 parent 7f739a0 commit 7cd28ca

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

scripts/bundles/helpers/jest/jest-preset.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ module.exports = {
2929
transform: {
3030
'^.+\\.(ts|tsx|jsx|css)$': path.join(testingDir, 'jest-preprocessor.js'),
3131
},
32+
watchPathIgnorePatterns: ['^.+\\.d\\.ts$'],
3233
};

src/testing/testing.ts

+43-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import type { CompilerBuildResults, Compiler, Config, DevServer, E2EProcessEnv, OutputTargetWww, Testing, TestingRunOptions } from '@stencil/core/internal';
1+
import type {
2+
CompilerBuildResults,
3+
Compiler,
4+
CompilerWatcher,
5+
Config,
6+
DevServer,
7+
E2EProcessEnv,
8+
OutputTargetWww,
9+
Testing,
10+
TestingRunOptions,
11+
} from '@stencil/core/internal';
212
import { getAppScriptUrl, getAppStyleUrl } from './testing-utils';
313
import { hasError } from '@utils';
414
import { runJest } from './jest/jest-runner';
@@ -20,11 +30,14 @@ export const createTesting = async (config: Config): Promise<Testing> => {
2030
let doScreenshots = false;
2131
let passed = false;
2232
let env: E2EProcessEnv;
33+
let compilerWatcher: CompilerWatcher = null;
2334
const msg: string[] = [];
2435

2536
try {
2637
if (!opts.spec && !opts.e2e) {
27-
config.logger.error(`Testing requires either the --spec or --e2e command line flags, or both. For example, to run unit tests, use the command: stencil test --spec`);
38+
config.logger.error(
39+
`Testing requires either the --spec or --e2e command line flags, or both. For example, to run unit tests, use the command: stencil test --spec`,
40+
);
2841
return false;
2942
}
3043

@@ -40,7 +53,7 @@ export const createTesting = async (config: Config): Promise<Testing> => {
4053
env.__STENCIL_SPEC_TESTS__ = 'true';
4154
}
4255

43-
config.logger.info(config.logger.magenta(`testing ${msg.join(' and ')} files`));
56+
config.logger.info(config.logger.magenta(`testing ${msg.join(' and ')} files${config.watch ? ' (watch)' : ''}`));
4457

4558
doScreenshots = !!(opts.e2e && opts.screenshot);
4659
if (doScreenshots) {
@@ -64,20 +77,37 @@ export const createTesting = async (config: Config): Promise<Testing> => {
6477
});
6578

6679
const doBuild = !(config.flags && config.flags.build === false);
80+
if (doBuild && config.watch) {
81+
compilerWatcher = await compiler.createWatcher();
82+
}
83+
6784
if (doBuild) {
68-
buildTask = compiler.build();
85+
if (compilerWatcher) {
86+
buildTask = new Promise(resolve => {
87+
const removeListener = compilerWatcher.on('buildFinish', buildResults => {
88+
removeListener();
89+
resolve(buildResults);
90+
});
91+
});
92+
compilerWatcher.start();
93+
} else {
94+
buildTask = compiler.build();
95+
}
6996
}
7097

7198
config.devServer.openBrowser = false;
7299
config.devServer.gzip = false;
73100
config.devServer.reloadStrategy = null;
74101

75-
const startupResults = await Promise.all([start(config.devServer, config.logger), startPuppeteerBrowser(config)]);
102+
const startupResults = await Promise.all([
103+
start(config.devServer, config.logger),
104+
startPuppeteerBrowser(config),
105+
]);
76106

77107
devServer = startupResults[0];
78108
puppeteerBrowser = startupResults[1];
79109

80-
if (doBuild) {
110+
if (buildTask) {
81111
const results = await buildTask;
82112
if (!results || (!config.watch && hasError(results && results.diagnostics))) {
83113
await destroy();
@@ -111,6 +141,9 @@ export const createTesting = async (config: Config): Promise<Testing> => {
111141
passed = await runJest(config, env);
112142
}
113143
config.logger.info('');
144+
if (compilerWatcher) {
145+
await compilerWatcher.close();
146+
}
114147
} catch (e) {
115148
config.logger.error(e);
116149
}
@@ -170,5 +203,9 @@ function setupTestingConfig(config: Config) {
170203
}
171204
});
172205

206+
if (config.flags.args.includes('--watchAll')) {
207+
config.watch = true;
208+
}
209+
173210
return config;
174211
}

0 commit comments

Comments
 (0)