Skip to content

Commit a2abaf7

Browse files
authored
test(e2e): add webpack support (#1208)
1 parent 30ae1f7 commit a2abaf7

14 files changed

+265
-17
lines changed

Diff for: e2e/renderer/app/items-accessor.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export class ItemsAccessor {
1111
this.items = this.itemsService.add(this.items);
1212
}
1313

14-
remove(item) {
14+
remove(item?: number) {
15+
item = item || this.items[this.items.length - 1];
1516
this.items = this.itemsService.remove(this.items, item);
1617
}
1718

Diff for: e2e/renderer/app/vendor-platform.android.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("application");
2+
if (!global["__snapshot"]) {
3+
// In case snapshot generation is enabled these modules will get into the bundle
4+
// but will not be required/evaluated.
5+
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
6+
// This way, they will be evaluated on app start as early as possible.
7+
require("ui/frame");
8+
require("ui/frame/activity");
9+
}

Diff for: e2e/renderer/app/vendor-platform.ios.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void 0;

Diff for: e2e/renderer/app/vendor.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Snapshot the ~/app.css and the theme
2+
const application = require("application");
3+
require("ui/styling/style-scope");
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
6+
application.loadAppCss();
7+
8+
require("./vendor-platform");
9+
10+
require("reflect-metadata");
11+
require("@angular/platform-browser");
12+
require("@angular/core");
13+
require("@angular/common");
14+
require("@angular/forms");
15+
require("@angular/http");
16+
require("@angular/router");
17+
18+
require("nativescript-angular/platform-static");
19+
require("nativescript-angular/forms");
20+
require("nativescript-angular/router");

Diff for: e2e/renderer/e2e/config/appium.capabilities.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@
8585
"platformName": "iOS",
8686
"platformVersion": "10.0",
8787
"deviceName": "iPhone 7 100",
88-
"noReset": false,
88+
"noReset": true,
8989
"fullReset": false,
9090
"app": ""
9191
},
9292
"sim.iPhone7.iOS110": {
9393
"platformName": "iOS",
94-
"platformVersion": "11.0",
94+
"platformVersion": "11.2",
9595
"deviceName": "iPhone 7 110",
96-
"noReset": false,
96+
"noReset": true,
9797
"fullReset": false,
9898
"app": ""
9999
}
100-
}
100+
}

Diff for: e2e/renderer/package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"nativescript": {
77
"id": "org.nativescript.renderer",
88
"tns-android": {
9-
"version": "next"
9+
"version": "3.4.1-2018-02-06-02"
1010
}
1111
},
1212
"dependencies": {
@@ -26,6 +26,8 @@
2626
"zone.js": "^0.8.4"
2727
},
2828
"devDependencies": {
29+
"@angular/compiler-cli": "~5.2.0",
30+
"@ngtools/webpack": "~1.9.4",
2931
"@types/chai": "^4.0.2",
3032
"@types/mocha": "^2.2.41",
3133
"@types/node": "^7.0.5",
@@ -35,18 +37,29 @@
3537
"chai": "~4.1.1",
3638
"chai-as-promised": "~7.1.1",
3739
"colors": "^1.1.2",
40+
"copy-webpack-plugin": "~4.3.0",
41+
"css-loader": "~0.28.7",
42+
"extract-text-webpack-plugin": "~3.0.2",
3843
"lazy": "1.0.11",
3944
"mocha": "~3.5.0",
4045
"mocha-junit-reporter": "^1.13.0",
4146
"mocha-multi": "^0.11.0",
4247
"nativescript-dev-appium": "next",
4348
"nativescript-dev-typescript": "~0.4.0",
49+
"nativescript-dev-webpack": "^0.9.2",
50+
"nativescript-worker-loader": "~0.8.1",
51+
"raw-loader": "~0.5.1",
52+
"resolve-url-loader": "~2.2.1",
4453
"tslib": "^1.7.1",
45-
"typescript": "~2.6.2"
54+
"typescript": "~2.6.2",
55+
"uglifyjs-webpack-plugin": "~1.1.6",
56+
"webpack": "~3.10.0",
57+
"webpack-bundle-analyzer": "^2.9.1",
58+
"webpack-sources": "~1.1.0"
4659
},
4760
"scripts": {
4861
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",
4962
"compile-tests-w": "tsc -p e2e --watch",
5063
"update-app-ng-deps": "update-app-ng-deps"
5164
}
52-
}
65+
}

Diff for: e2e/renderer/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"exclude": [
2323
"node_modules",
2424
"platforms",
25-
"**/*.aot.ts",
2625
"e2e"
2726
]
28-
}
27+
}

Diff for: e2e/renderer/webpack.config.js

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
const { resolve, join } = require("path");
2+
3+
const webpack = require("webpack");
4+
const nsWebpack = require("nativescript-dev-webpack");
5+
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6+
const CopyWebpackPlugin = require("copy-webpack-plugin");
7+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
8+
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
9+
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
10+
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
11+
12+
module.exports = env => {
13+
const platform = env && (env.android && "android" || env.ios && "ios");
14+
if (!platform) {
15+
throw new Error("You need to provide a target platform!");
16+
}
17+
const platforms = ["ios", "android"];
18+
const { snapshot, uglify, report, aot } = env;
19+
const ngToolsWebpackOptions = { tsConfigPath: "tsconfig.json" };
20+
21+
const config = {
22+
context: resolve("./app"),
23+
target: nativescriptTarget,
24+
entry: {
25+
bundle: aot ? "./main.aot.ts" : "./main.ts",
26+
vendor: "./vendor",
27+
},
28+
output: {
29+
pathinfo: true,
30+
// Default destination inside platforms/<platform>/...
31+
path: resolve(nsWebpack.getAppPath(platform)),
32+
libraryTarget: "commonjs2",
33+
filename: "[name].js",
34+
},
35+
resolve: {
36+
extensions: [".ts", ".js", ".scss", ".css"],
37+
// Resolve {N} system modules from tns-core-modules
38+
modules: [
39+
"node_modules/tns-core-modules",
40+
"node_modules",
41+
],
42+
alias: {
43+
'~': resolve("./app")
44+
},
45+
// don't resolve symlinks to symlinked modules
46+
symlinks: false
47+
},
48+
resolveLoader: {
49+
// don't resolve symlinks to symlinked loaders
50+
symlinks: false
51+
},
52+
node: {
53+
// Disable node shims that conflict with NativeScript
54+
"http": false,
55+
"timers": false,
56+
"setImmediate": false,
57+
"fs": "empty",
58+
},
59+
module: {
60+
rules: [
61+
{ test: /\.html$|\.xml$/, use: "raw-loader" },
62+
63+
// tns-core-modules reads the app.css and its imports using css-loader
64+
{
65+
test: /[\/|\\]app\.css$/,
66+
use: {
67+
loader: "css-loader",
68+
options: { minimize: false, url: false },
69+
}
70+
},
71+
{
72+
test: /[\/|\\]app\.scss$/,
73+
use: [
74+
{ loader: "css-loader", options: { minimize: false, url: false } },
75+
"sass-loader"
76+
]
77+
},
78+
79+
// Angular components reference css files and their imports using raw-loader
80+
{ test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
81+
{ test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
82+
83+
// Compile TypeScript files with ahead-of-time compiler.
84+
{ test: /.ts$/, use: [
85+
"nativescript-dev-webpack/moduleid-compat-loader",
86+
{ loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
87+
]},
88+
],
89+
},
90+
plugins: [
91+
// Vendor libs go to the vendor.js chunk
92+
new webpack.optimize.CommonsChunkPlugin({
93+
name: ["vendor"],
94+
}),
95+
// Define useful constants like TNS_WEBPACK
96+
new webpack.DefinePlugin({
97+
"global.TNS_WEBPACK": "true",
98+
}),
99+
// Copy assets to out dir. Add your own globs as needed.
100+
new CopyWebpackPlugin([
101+
{ from: "App_Resources/**" },
102+
{ from: "fonts/**" },
103+
{ from: "**/*.jpg" },
104+
{ from: "**/*.png" },
105+
{ from: "**/*.xml" },
106+
]),
107+
// Generate a bundle starter script and activate it in package.json
108+
new nsWebpack.GenerateBundleStarterPlugin([
109+
"./vendor",
110+
"./bundle",
111+
]),
112+
// Support for web workers since v3.2
113+
new NativeScriptWorkerPlugin(),
114+
// AngularCompilerPlugin with augmented NativeScript filesystem to handle platform specific resource resolution.
115+
new nsWebpack.NativeScriptAngularCompilerPlugin(
116+
Object.assign({
117+
entryModule: resolve(__dirname, "app/app.module#AppModule"),
118+
skipCodeGeneration: !aot,
119+
platformOptions: {
120+
platform,
121+
platforms,
122+
// ignore: ["App_Resources"]
123+
},
124+
}, ngToolsWebpackOptions)
125+
),
126+
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
127+
new nsWebpack.WatchStateLoggerPlugin(),
128+
],
129+
};
130+
if (report) {
131+
// Generate report files for bundles content
132+
config.plugins.push(new BundleAnalyzerPlugin({
133+
analyzerMode: "static",
134+
openAnalyzer: false,
135+
generateStatsFile: true,
136+
reportFilename: join(__dirname, "report", `report.html`),
137+
statsFilename: join(__dirname, "report", `stats.json`),
138+
}));
139+
}
140+
if (snapshot) {
141+
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
142+
chunk: "vendor",
143+
projectRoot: __dirname,
144+
webpackConfig: config,
145+
targetArchs: ["arm", "arm64", "ia32"],
146+
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
147+
useLibs: false
148+
}));
149+
}
150+
if (uglify) {
151+
config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
152+
153+
// Work around an Android issue by setting compress = false
154+
const compress = platform !== "android";
155+
config.plugins.push(new UglifyJsPlugin({
156+
uglifyOptions: {
157+
mangle: { reserved: nsWebpack.uglifyMangleExcludes },
158+
compress,
159+
}
160+
}));
161+
}
162+
return config;
163+
};

Diff for: e2e/router/app/vendor-platform.android.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("application");
2+
if (!global["__snapshot"]) {
3+
// In case snapshot generation is enabled these modules will get into the bundle
4+
// but will not be required/evaluated.
5+
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
6+
// This way, they will be evaluated on app start as early as possible.
7+
require("ui/frame");
8+
require("ui/frame/activity");
9+
}

Diff for: e2e/router/app/vendor-platform.ios.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void 0;

Diff for: e2e/router/app/vendor.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Snapshot the ~/app.css and the theme
2+
const application = require("application");
3+
require("ui/styling/style-scope");
4+
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
5+
global.registerWebpackModules(appCssContext);
6+
application.loadAppCss();
7+
8+
require("./vendor-platform");
9+
10+
require("reflect-metadata");
11+
require("@angular/platform-browser");
12+
require("@angular/core");
13+
require("@angular/common");
14+
require("@angular/forms");
15+
require("@angular/http");
16+
require("@angular/router");
17+
18+
require("nativescript-angular/platform-static");
19+
require("nativescript-angular/forms");
20+
require("nativescript-angular/router");

Diff for: e2e/router/e2e/config/appium.capabilities.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@
8585
"platformName": "iOS",
8686
"platformVersion": "10.0",
8787
"deviceName": "iPhone 7 100",
88-
"noReset": false,
88+
"noReset": true,
8989
"fullReset": false,
9090
"app": ""
9191
},
9292
"sim.iPhone7.iOS110": {
9393
"platformName": "iOS",
94-
"platformVersion": "11.0",
94+
"platformVersion": "11.2",
9595
"deviceName": "iPhone 7 110",
96-
"noReset": false,
96+
"noReset": true,
9797
"fullReset": false,
9898
"app": ""
9999
}
100-
}
100+
}

Diff for: e2e/router/package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"zone.js": "^0.8.4"
3131
},
3232
"devDependencies": {
33+
"@angular/compiler-cli": "~5.2.0",
34+
"@ngtools/webpack": "~1.9.4",
3335
"@types/chai": "^4.0.2",
3436
"@types/mocha": "^2.2.41",
3537
"@types/node": "^7.0.5",
@@ -39,14 +41,25 @@
3941
"chai": "~4.1.1",
4042
"chai-as-promised": "~7.1.1",
4143
"colors": "^1.1.2",
44+
"copy-webpack-plugin": "~4.3.0",
45+
"css-loader": "~0.28.7",
46+
"extract-text-webpack-plugin": "~3.0.2",
4247
"lazy": "1.0.11",
4348
"mocha": "~3.5.0",
4449
"mocha-junit-reporter": "^1.13.0",
4550
"mocha-multi": "^0.11.0",
4651
"nativescript-dev-appium": "next",
4752
"nativescript-dev-typescript": "~0.4.0",
53+
"nativescript-dev-webpack": "^0.9.2",
54+
"nativescript-worker-loader": "~0.8.1",
55+
"raw-loader": "~0.5.1",
56+
"resolve-url-loader": "~2.2.1",
4857
"tslib": "^1.7.1",
49-
"typescript": "~2.6.2"
58+
"typescript": "~2.6.2",
59+
"uglifyjs-webpack-plugin": "~1.1.6",
60+
"webpack": "~3.10.0",
61+
"webpack-bundle-analyzer": "^2.9.1",
62+
"webpack-sources": "~1.1.0"
5063
},
5164
"scripts": {
5265
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",

Diff for: e2e/router/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"exclude": [
2323
"node_modules",
2424
"platforms",
25-
"**/*.aot.ts",
2625
"e2e"
2726
]
28-
}
27+
}

0 commit comments

Comments
 (0)