Last active
December 4, 2016 13:09
-
-
Save perry-mitchell/e6838b21e4214a8ab016865c23c62f6c to your computer and use it in GitHub Desktop.
Webpack 2 + inject-loader 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": "es2015" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { testA } from "filea"; | |
export function getValue() { | |
return testA() * 2; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function testA() { | |
return __VALUEA__; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(config) { | |
config.set({ | |
// base path that will be used to resolve all patterns (eg. files, exclude) | |
basePath: '', | |
// frameworks to use | |
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | |
frameworks: ['mocha', 'chai', 'sinon'], | |
// list of files / patterns to load in the browser | |
files: [ | |
'dist/test.js' | |
], | |
// list of files to exclude | |
exclude: [ | |
], | |
// preprocess matching files before serving them to the browser | |
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | |
preprocessors: {}, | |
// preprocessors: { | |
// "unitTests/index.js": ["webpack", "sourcemap"] | |
// }, | |
// webpack: require("./webpack/build-tests.js"), | |
// test results reporter to use | |
// possible values: 'dots', 'progress' | |
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | |
reporters: ['progress'], | |
// web server port | |
port: 9876, | |
// enable / disable colors in the output (reporters and logs) | |
colors: true, | |
// level of logging | |
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | |
logLevel: config.LOG_INFO, | |
// enable / disable watching file and executing tests whenever any file changes | |
autoWatch: true, | |
// start these browsers | |
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | |
browsers: ['ChromeWithoutSecurity'], | |
customLaunchers: { | |
ChromeWithoutSecurity: { | |
base: 'Chrome', | |
flags: ['--disable-web-security'] | |
} | |
}, | |
// Continuous Integration mode | |
// if true, Karma captures browsers, runs the tests and exits | |
singleRun: true, | |
// Concurrency level | |
// how many browser should be started simultaneous | |
concurrency: Infinity | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Main", function() { | |
beforeEach(function() { | |
let fileInjector = require("inject-loader!entry"); | |
this.entry = fileInjector({ | |
"filea": { | |
testA: function() { | |
return 1; | |
} | |
} | |
}); | |
}); | |
it("works without override", function() { | |
expect(require("entry.js").getValue()).to.equal(20); | |
}); | |
it("overrides", function() { | |
expect(this.entry.getValue()).to.equal(2); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "inject-loader-v3-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"build": "webpack --progress", | |
"test": "npm run build && karma start" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"babel-core": "^6.18.2", | |
"babel-loader": "^6.2.8", | |
"babel-plugin-transform-es2015-classes": "^6.18.0", | |
"babel-plugin-transform-es2015-object-super": "^6.8.0", | |
"babel-plugin-transform-object-assign": "^6.8.0", | |
"babel-plugin-transform-object-rest-spread": "^6.19.0", | |
"babel-plugin-transform-strict-mode": "^6.18.0", | |
"babel-preset-es2015": "^6.18.0", | |
"inject-loader": "3.0.0-beta2", | |
"webpack": "2.1.0-beta.27" | |
}, | |
"devDependencies": { | |
"chai": "^3.5.0", | |
"karma": "^1.3.0", | |
"karma-chai": "^0.1.0", | |
"karma-chrome-launcher": "^2.0.0", | |
"karma-mocha": "^1.3.0", | |
"karma-sinon": "^1.0.5", | |
"mocha": "^3.2.0", | |
"sinon": "^1.17.6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const webpack = require("webpack"); | |
module.exports = { | |
entry: { | |
script: path.resolve(__dirname, "./main.spec.js") | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
use: "babel-loader", | |
exclude: /(\/node_modules\/|test\.js|\.spec\.js$)/ | |
} | |
] | |
}, | |
node: { | |
setImmediate: false | |
}, | |
output: { | |
path: "./dist", | |
filename: "test.js", | |
pathinfo: true | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
__VALUEA__: 10 | |
}) | |
], | |
resolve: { | |
extensions: [".js"], | |
modules: [ | |
__dirname, | |
path.resolve(__dirname, "./node_modules") | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment