forked from heremaps/harp.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.tests.config.js
More file actions
158 lines (148 loc) · 5.39 KB
/
Copy pathwebpack.tests.config.js
File metadata and controls
158 lines (148 loc) · 5.39 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright (C) 2017-2020 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/
//@ts-check
const webpack = require("webpack");
const glob = require("glob");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
const testResourceDirs = glob.sync(path.join(__dirname, "@here/*/test/resources"));
const testResources = testResourceDirs.map(dir => {
return {
from: dir,
to: path.relative(__dirname, dir)
};
});
const harpMapThemePath = path.dirname(require.resolve("@here/harp-map-theme/package.json"));
const harpDataSourceProtocolPath = path.dirname(
require.resolve("@here/harp-datasource-protocol/package.json")
);
const harpFontResourcesPath = path.dirname(require.resolve("@here/harp-fontcatalog/package.json"));
const allTests = [
...glob.sync("@here/*/test/**/*.ts"),
...glob.sync("./test/performance/**/*.ts"),
...glob.sync("./test/rendering/*.ts")
];
const unitTests = allTests.filter(
name => name.indexOf("/rendering") === -1 && name.indexOf("/performance/") === -1
);
const performanceTests = allTests.filter(name => name.indexOf("/performance/") > -1);
const renderingTests = allTests.filter(name => name.indexOf("/rendering/") > -1);
/** @type{webpack.Configuration} */
const browserTestsConfig = {
devtool: "source-map",
resolve: {
extensions: [".webpack.js", ".web.ts", ".ts", ".tsx", ".web.js", ".js"],
modules: [".", "node_modules"]
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
onlyCompileBundledFiles: true,
// use the main tsconfig.json for all compilation
configFile: path.resolve(__dirname, "tsconfig.json")
}
}
]
},
entry: {
test: unitTests,
"performance-test": performanceTests,
"rendering-test": renderingTests
},
output: {
path: path.join(__dirname, "dist/test"),
filename: "[name].bundle.js"
},
plugins: [
new webpack.EnvironmentPlugin({
// default NODE_ENV to development. Override by setting the environment variable NODE_ENV to 'production'
NODE_ENV: process.env.NODE_ENV || "development"
}),
new CopyWebpackPlugin({
patterns: [
path.join(__dirname, "test/index.html"),
path.join(__dirname, "test/rendering.html"),
path.join(__dirname, "test/performance.html"),
require.resolve("three/build/three.min.js"),
require.resolve("mocha/mocha.js"),
require.resolve("mocha/mocha.css"),
require.resolve("mocha-webdriver-runner/dist/mocha-webdriver-client.js"),
...testResources,
{
// DefaultThemeTest is expecting the themes to be in:
// http://localhost:8080/@here/harp-map-theme/resources/berlin_*.json
// FIXME: CopyWebpackPlugin is not properly handling absolute path on Windows
// from: path.join(harpMapThemePath, "resources/berlin*.json"),
from: "@here/harp-map-theme/resources/berlin_*.json",
toType: "dir"
},
{
from: path.join(harpMapThemePath, "resources/wests_textures"),
to: "resources/wests_textures",
toType: "dir"
},
{
from: path.join(harpDataSourceProtocolPath, "theme.schema.json"),
to: "./@here/harp-datasource-protocol",
toType: "dir"
},
{
from: path.join(harpFontResourcesPath, "resources"),
to: "@here/harp-fontcatalog/resources"
},
{
from: "./test/resources/",
to: "dist/resources",
toType: "dir"
}
]
})
],
externals: [
{
fs: "undefined",
perf_hooks: "undefined",
three: "THREE",
typescript: "undefined"
},
function(context, request, callback) {
return /three\.module\.js$/.test(request)
? callback(null, "THREE")
: callback(undefined, undefined);
}
],
performance: {
hints: false
},
devServer: {
before: function(app) {
require("ts-node/register");
const RenderingTestResultServer = require("./@here/harp-test-utils/lib/rendering/RenderingTestResultServer");
const basePath = "./rendering-test-results/";
RenderingTestResultServer.installMiddleware(app, basePath);
},
contentBase: "./test/"
},
stats: {
all: false,
timings: true,
exclude: "/resources/",
errors: true,
entrypoints: true,
warnings: true
},
// @ts-ignore
mode: process.env.NODE_ENV || "development"
};
if (!process.env.HARP_NO_HARD_SOURCE_CACHE) {
browserTestsConfig.plugins.push(new HardSourceWebpackPlugin());
}
module.exports = browserTestsConfig;