Skip to content

Commit

Permalink
test with real webpack environment
Browse files Browse the repository at this point in the history
  • Loading branch information
nino-porcino authored and nino-porcino committed Aug 27, 2017
1 parent 0a667d4 commit ffaa076
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -7,10 +7,11 @@
"@types/jasmine": "^2.5.43",
"@types/node": "^7.0.5",
"jasmine": "^2.5.3",
"typescript": "^2.2.1"
"typescript": "^2.2.1",
"webpack": "^3.5.5"
},
"scripts": {
"test": "tsc & jasmine --no-color"
"test": "node node_modules/webpack/bin/webpack.js & tsc & jasmine --no-color"
},
"author": "Antonino Porcino <nino.porcino@gmail.com>",
"contributors": [
Expand Down
1 change: 1 addition & 0 deletions spec/data/webpack.in.js
@@ -0,0 +1 @@
const dummy = require("./webpack.in.module.js")
16 changes: 16 additions & 0 deletions spec/data/webpack.in.module.js
@@ -0,0 +1,16 @@
/// #if DEBUG
assert(DEBUG === true)
/// #endif

/// #if version < 2
assert(version < 2)
/// #endif

/// #if !DEBUG
assert(DEBUG === undefined || DEBUG == false)
/// #endif

/// #if version > 2
assert(version > 2)
/// #endif

95 changes: 95 additions & 0 deletions spec/data/webpack.out.actual.js
@@ -0,0 +1,95 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(this, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

const dummy = __webpack_require__(1)

/***/ }),
/* 1 */
/***/ (function(module, exports) {

/// #if DEBUG
assert(DEBUG === true)
/// #endif

/// #if version < 2
assert(version < 2)
/// #endif

/// #if !DEBUG
assert(DEBUG === undefined || DEBUG == false)
/// #endif

/// #if version > 2
assert(version > 2)
/// #endif



/***/ })
/******/ ])));
95 changes: 95 additions & 0 deletions spec/data/webpack.out.js
@@ -0,0 +1,95 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(this, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

const dummy = __webpack_require__(1)

/***/ }),
/* 1 */
/***/ (function(module, exports) {

/// #if DEBUG
assert(DEBUG === true)
/// #endif

/// #if version < 2
assert(version < 2)
/// #endif

/// #if !DEBUG
assert(DEBUG === undefined || DEBUG == false)
/// #endif

/// #if version > 2
assert(version > 2)
/// #endif



/***/ })
/******/ ])));
20 changes: 20 additions & 0 deletions spec/processSpec.ts
Expand Up @@ -58,3 +58,23 @@ describe("files spec", ()=> {

});

describe("webpack bundle", ()=>{
const files = [ "webpack" ];

const fileSet = files.map(fn => ({
input: `spec/data/${fn}.in.js`,
output: `spec/data/${fn}.out.js`,
actual: `spec/data/${fn}.out.actual.js`
}));

// checks spec files as terminating in CRLF (windows)
fileSet.forEach( ({ input, output, actual })=> {
it(`build correctly on ${input}`, ()=> {
const inFile = read(input);
const actualFile = read(actual);
const expectedFile = read(output);
expect(actualFile).toEqual(expectedFile);
});
});

});
52 changes: 52 additions & 0 deletions webpack.config.js
@@ -0,0 +1,52 @@
/*
* This file is used to test ifdef-loader on a real webpack environment.
* It reads "spec/data/webpack.in.js" and outputs "spec/data/webpack.out.actual.js"
* which is later compared with "spec/data/webpack.out.js"
*
*/

const opts = {
DEBUG: true,
version: 3,
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": true // add this to use double slash comment instead of default triple slash
};

// if using query strings
const q = require('querystring').encode(opts);

/************************************************************/

const webpack = require('webpack');

module.exports = function(env)
{
const entry = "./spec/data/webpack.in.js";

const loaders = [{
test: /\.in\.js$/,
exclude: /node_modules/,
use: [{
loader: `${__dirname}/ifdef-loader`,
options: opts
}]
// alternate:
// loader: `${__dirname}/ifdef-loader?query=${q}`,
}];

let config =
{
module: { rules: loaders },
entry: entry,
cache: true,

output: {
libraryTarget: "this",
path: `${__dirname}/spec/data`,
filename: "webpack.out.actual.js",
}
};

return config;
};

0 comments on commit ffaa076

Please sign in to comment.