Skip to content

test(e2e): add webpack support #1208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/renderer/app/items-accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class ItemsAccessor {
this.items = this.itemsService.add(this.items);
}

remove(item) {
remove(item?: number) {
item = item || this.items[this.items.length - 1];
this.items = this.itemsService.remove(this.items, item);
}

Expand Down
9 changes: 9 additions & 0 deletions e2e/renderer/app/vendor-platform.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("application");
if (!global["__snapshot"]) {
// In case snapshot generation is enabled these modules will get into the bundle
// but will not be required/evaluated.
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
// This way, they will be evaluated on app start as early as possible.
require("ui/frame");
require("ui/frame/activity");
}
1 change: 1 addition & 0 deletions e2e/renderer/app/vendor-platform.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void 0;
20 changes: 20 additions & 0 deletions e2e/renderer/app/vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Snapshot the ~/app.css and the theme
const application = require("application");
require("ui/styling/style-scope");
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
global.registerWebpackModules(appCssContext);
application.loadAppCss();

require("./vendor-platform");

require("reflect-metadata");
require("@angular/platform-browser");
require("@angular/core");
require("@angular/common");
require("@angular/forms");
require("@angular/http");
require("@angular/router");

require("nativescript-angular/platform-static");
require("nativescript-angular/forms");
require("nativescript-angular/router");
8 changes: 4 additions & 4 deletions e2e/renderer/e2e/config/appium.capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
"platformName": "iOS",
"platformVersion": "10.0",
"deviceName": "iPhone 7 100",
"noReset": false,
"noReset": true,
"fullReset": false,
"app": ""
},
"sim.iPhone7.iOS110": {
"platformName": "iOS",
"platformVersion": "11.0",
"platformVersion": "11.2",
"deviceName": "iPhone 7 110",
"noReset": false,
"noReset": true,
"fullReset": false,
"app": ""
}
}
}
19 changes: 16 additions & 3 deletions e2e/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"nativescript": {
"id": "org.nativescript.renderer",
"tns-android": {
"version": "next"
"version": "3.4.1-2018-02-06-02"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next?

}
},
"dependencies": {
Expand All @@ -26,6 +26,8 @@
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "~5.2.0",
"@ngtools/webpack": "~1.9.4",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
Expand All @@ -35,18 +37,29 @@
"chai": "~4.1.1",
"chai-as-promised": "~7.1.1",
"colors": "^1.1.2",
"copy-webpack-plugin": "~4.3.0",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
"mocha-multi": "^0.11.0",
"nativescript-dev-appium": "next",
"nativescript-dev-typescript": "~0.4.0",
"nativescript-dev-webpack": "^0.9.2",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"tslib": "^1.7.1",
"typescript": "~2.6.2"
"typescript": "~2.6.2",
"uglifyjs-webpack-plugin": "~1.1.6",
"webpack": "~3.10.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "~1.1.0"
},
"scripts": {
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",
"compile-tests-w": "tsc -p e2e --watch",
"update-app-ng-deps": "update-app-ng-deps"
}
}
}
3 changes: 1 addition & 2 deletions e2e/renderer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts",
"e2e"
]
}
}
163 changes: 163 additions & 0 deletions e2e/renderer/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
const { resolve, join } = require("path");

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");

module.exports = env => {
const platform = env && (env.android && "android" || env.ios && "ios");
if (!platform) {
throw new Error("You need to provide a target platform!");
}
const platforms = ["ios", "android"];
const { snapshot, uglify, report, aot } = env;
const ngToolsWebpackOptions = { tsConfigPath: "tsconfig.json" };

const config = {
context: resolve("./app"),
target: nativescriptTarget,
entry: {
bundle: aot ? "./main.aot.ts" : "./main.ts",
vendor: "./vendor",
},
output: {
pathinfo: true,
// Default destination inside platforms/<platform>/...
path: resolve(nsWebpack.getAppPath(platform)),
libraryTarget: "commonjs2",
filename: "[name].js",
},
resolve: {
extensions: [".ts", ".js", ".scss", ".css"],
// Resolve {N} system modules from tns-core-modules
modules: [
"node_modules/tns-core-modules",
"node_modules",
],
alias: {
'~': resolve("./app")
},
// don't resolve symlinks to symlinked modules
symlinks: false
},
resolveLoader: {
// don't resolve symlinks to symlinked loaders
symlinks: false
},
node: {
// Disable node shims that conflict with NativeScript
"http": false,
"timers": false,
"setImmediate": false,
"fs": "empty",
},
module: {
rules: [
{ test: /\.html$|\.xml$/, use: "raw-loader" },

// tns-core-modules reads the app.css and its imports using css-loader
{
test: /[\/|\\]app\.css$/,
use: {
loader: "css-loader",
options: { minimize: false, url: false },
}
},
{
test: /[\/|\\]app\.scss$/,
use: [
{ loader: "css-loader", options: { minimize: false, url: false } },
"sass-loader"
]
},

// Angular components reference css files and their imports using raw-loader
{ test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
{ test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },

// Compile TypeScript files with ahead-of-time compiler.
{ test: /.ts$/, use: [
"nativescript-dev-webpack/moduleid-compat-loader",
{ loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
]},
],
},
plugins: [
// Vendor libs go to the vendor.js chunk
new webpack.optimize.CommonsChunkPlugin({
name: ["vendor"],
}),
// Define useful constants like TNS_WEBPACK
new webpack.DefinePlugin({
"global.TNS_WEBPACK": "true",
}),
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
{ from: "App_Resources/**" },
{ from: "fonts/**" },
{ from: "**/*.jpg" },
{ from: "**/*.png" },
{ from: "**/*.xml" },
]),
// Generate a bundle starter script and activate it in package.json
new nsWebpack.GenerateBundleStarterPlugin([
"./vendor",
"./bundle",
]),
// Support for web workers since v3.2
new NativeScriptWorkerPlugin(),
// AngularCompilerPlugin with augmented NativeScript filesystem to handle platform specific resource resolution.
new nsWebpack.NativeScriptAngularCompilerPlugin(
Object.assign({
entryModule: resolve(__dirname, "app/app.module#AppModule"),
skipCodeGeneration: !aot,
platformOptions: {
platform,
platforms,
// ignore: ["App_Resources"]
},
}, ngToolsWebpackOptions)
),
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
new nsWebpack.WatchStateLoggerPlugin(),
],
};
if (report) {
// Generate report files for bundles content
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: "static",
openAnalyzer: false,
generateStatsFile: true,
reportFilename: join(__dirname, "report", `report.html`),
statsFilename: join(__dirname, "report", `stats.json`),
}));
}
if (snapshot) {
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
chunk: "vendor",
projectRoot: __dirname,
webpackConfig: config,
targetArchs: ["arm", "arm64", "ia32"],
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
useLibs: false
}));
}
if (uglify) {
config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));

// Work around an Android issue by setting compress = false
const compress = platform !== "android";
config.plugins.push(new UglifyJsPlugin({
uglifyOptions: {
mangle: { reserved: nsWebpack.uglifyMangleExcludes },
compress,
}
}));
}
return config;
};
9 changes: 9 additions & 0 deletions e2e/router/app/vendor-platform.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("application");
if (!global["__snapshot"]) {
// In case snapshot generation is enabled these modules will get into the bundle
// but will not be required/evaluated.
// The snapshot webpack plugin will add them to the tns-java-classes.js bundle file.
// This way, they will be evaluated on app start as early as possible.
require("ui/frame");
require("ui/frame/activity");
}
1 change: 1 addition & 0 deletions e2e/router/app/vendor-platform.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void 0;
20 changes: 20 additions & 0 deletions e2e/router/app/vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Snapshot the ~/app.css and the theme
const application = require("application");
require("ui/styling/style-scope");
const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sass)$/);
global.registerWebpackModules(appCssContext);
application.loadAppCss();

require("./vendor-platform");

require("reflect-metadata");
require("@angular/platform-browser");
require("@angular/core");
require("@angular/common");
require("@angular/forms");
require("@angular/http");
require("@angular/router");

require("nativescript-angular/platform-static");
require("nativescript-angular/forms");
require("nativescript-angular/router");
8 changes: 4 additions & 4 deletions e2e/router/e2e/config/appium.capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
"platformName": "iOS",
"platformVersion": "10.0",
"deviceName": "iPhone 7 100",
"noReset": false,
"noReset": true,
"fullReset": false,
"app": ""
},
"sim.iPhone7.iOS110": {
"platformName": "iOS",
"platformVersion": "11.0",
"platformVersion": "11.2",
"deviceName": "iPhone 7 110",
"noReset": false,
"noReset": true,
"fullReset": false,
"app": ""
}
}
}
15 changes: 14 additions & 1 deletion e2e/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "~5.2.0",
"@ngtools/webpack": "~1.9.4",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
Expand All @@ -39,14 +41,25 @@
"chai": "~4.1.1",
"chai-as-promised": "~7.1.1",
"colors": "^1.1.2",
"copy-webpack-plugin": "~4.3.0",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
"mocha-multi": "^0.11.0",
"nativescript-dev-appium": "next",
"nativescript-dev-typescript": "~0.4.0",
"nativescript-dev-webpack": "^0.9.2",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"tslib": "^1.7.1",
"typescript": "~2.6.2"
"typescript": "~2.6.2",
"uglifyjs-webpack-plugin": "~1.1.6",
"webpack": "~3.10.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "~1.1.0"
},
"scripts": {
"e2e": "tsc -p e2e && mocha --opts ./e2e/config/mocha.opts",
Expand Down
3 changes: 1 addition & 2 deletions e2e/router/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts",
"e2e"
]
}
}