-
Notifications
You must be signed in to change notification settings - Fork 520
/
integration-test-build.ts
59 lines (49 loc) · 1.88 KB
/
integration-test-build.ts
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
// SPDX-FileCopyrightText: Copyright (C) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<[email protected]>
// SPDX-License-Identifier: MPL-2.0
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import path from "path";
import webpack from "webpack";
import webpackConfigDesktop from "./desktop/webpack.config";
import webpackConfigWeb from "./web/webpack.config";
if (process.env.TARGET !== "desktop" && process.env.TARGET !== "web") {
throw new Error("TARGET env variable must be either 'desktop' or 'web'");
}
const target = process.env.TARGET;
const appPath = path.join(__dirname, target, ".webpack");
export { appPath };
// global jest test setup builds the webpack build before running any integration tests
export default async (): Promise<void> => {
if ((process.env.INTEGRATION_SKIP_BUILD ?? "") !== "") {
return;
}
const webpackConfig = target === "desktop" ? webpackConfigDesktop : webpackConfigWeb;
const compiler = webpack(
webpackConfig.map((config) => {
if (typeof config === "function") {
return config(undefined, { mode: "production" });
}
return config;
}),
);
await new Promise<void>((resolve, reject) => {
// eslint-disable-next-line no-restricted-syntax
console.info(`\nBuilding Webpack (${target}). To skip, set INTEGRATION_SKIP_BUILD=1`);
compiler.run((err, result) => {
compiler.close(() => {});
if (err) {
reject(err);
return;
}
if (!result || result.hasErrors()) {
console.error(result?.toString());
reject(new Error("webpack build failed"));
return;
}
// eslint-disable-next-line no-restricted-syntax
console.info("Webpack build complete");
resolve();
});
});
};