forked from heremaps/harp.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.tests.config.js
132 lines (125 loc) · 4.5 KB
/
webpack.tests.config.js
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
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);
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 HardSourceWebpackPlugin(),
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([
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,
path.join(harpMapThemePath, "resources/berlin*.json"),
{
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();
}
],
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
},
mode: process.env.NODE_ENV || "development"
};
module.exports = browserTestsConfig;