├── test ├── server │ └── index.js ├── client │ ├── expose-loader │ │ └── stuff.js │ ├── index.js │ ├── worker-loader │ │ ├── identitiy.js │ │ └── worker.js │ ├── expose.js │ └── worker.js ├── client-tests.js ├── server-tests.js ├── shared │ ├── imports-loader │ │ ├── file.js │ │ ├── import-test-file.js │ │ ├── node_modules │ │ │ ├── moduleA.js │ │ │ └── moduleB.js │ │ ├── import-test-file.coffee │ │ └── import-test-file2.js │ ├── index.js │ ├── exports-loader │ │ └── stuff.js │ ├── json5-loader │ │ ├── testfile.json │ │ └── testfile.json5 │ ├── json5.js │ ├── exports.js │ └── imports.js └── cover-client-tests.js ├── .gitignore ├── .gitattributes ├── .travis.yml ├── bin ├── enhanced-require.js ├── enhanced-require-hot-watch.js └── webpack-dev-server.js ├── index.html ├── enhanced-require.config.js ├── webpack.config.js ├── cover-webpack.config.js ├── README.md ├── package.json └── Gruntfile.js /test/server/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /assets -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.json5 eol=lf 3 | -------------------------------------------------------------------------------- /test/client/expose-loader/stuff.js: -------------------------------------------------------------------------------- 1 | module.exports = "ABC"; 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.6 4 | - 0.8 -------------------------------------------------------------------------------- /test/client-tests.js: -------------------------------------------------------------------------------- 1 | require("./shared/"); 2 | require("./client/"); -------------------------------------------------------------------------------- /test/client/index.js: -------------------------------------------------------------------------------- 1 | require("./worker"); 2 | require("./expose"); -------------------------------------------------------------------------------- /test/server-tests.js: -------------------------------------------------------------------------------- 1 | require("./shared/"); 2 | require("./server/"); -------------------------------------------------------------------------------- /test/shared/imports-loader/file.js: -------------------------------------------------------------------------------- 1 | module.exports = { file: true }; -------------------------------------------------------------------------------- /bin/enhanced-require.js: -------------------------------------------------------------------------------- 1 | require("enhanced-require/bin/enhanced-require"); -------------------------------------------------------------------------------- /test/shared/imports-loader/import-test-file.js: -------------------------------------------------------------------------------- 1 | module.exports = moduleA; -------------------------------------------------------------------------------- /bin/enhanced-require-hot-watch.js: -------------------------------------------------------------------------------- 1 | require("enhanced-require/bin/hot-watch"); -------------------------------------------------------------------------------- /bin/webpack-dev-server.js: -------------------------------------------------------------------------------- 1 | require("webpack-dev-server/bin/webpack-dev-server"); -------------------------------------------------------------------------------- /test/shared/imports-loader/node_modules/moduleA.js: -------------------------------------------------------------------------------- 1 | module.exports = { module: true }; -------------------------------------------------------------------------------- /test/shared/imports-loader/node_modules/moduleB.js: -------------------------------------------------------------------------------- 1 | module.exports = { moduleB: true }; -------------------------------------------------------------------------------- /test/shared/index.js: -------------------------------------------------------------------------------- 1 | require("./imports"); 2 | require("./json5"); 3 | require("./exports"); -------------------------------------------------------------------------------- /test/client/worker-loader/identitiy.js: -------------------------------------------------------------------------------- 1 | module.exports = function(value) { 2 | return value; 3 | }; -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /test/cover-client-tests.js: -------------------------------------------------------------------------------- 1 | require("./client-tests"); 2 | 3 | after(function() { 4 | require("coverjs-loader").reportHtml(); 5 | }); -------------------------------------------------------------------------------- /test/shared/imports-loader/import-test-file.coffee: -------------------------------------------------------------------------------- 1 | i = 1 + 1; 2 | j = i + i; 3 | identity = (a) -> a 4 | module.exports = identity moduleA -------------------------------------------------------------------------------- /test/shared/imports-loader/import-test-file2.js: -------------------------------------------------------------------------------- 1 | exports.moduleA = moduleA; 2 | exports.moduleB = moduleB; 3 | exports.moduleC = moduleC; -------------------------------------------------------------------------------- /enhanced-require.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | module: { 3 | loaders: [ 4 | { test: /\.json$/, loader: "json" }, 5 | { test: /\.coffee$/, loader: "coffee-loader" } 6 | ] 7 | } 8 | } -------------------------------------------------------------------------------- /test/shared/exports-loader/stuff.js: -------------------------------------------------------------------------------- 1 | var a = "a"; 2 | var b = "b"; 3 | var c = "c"; 4 | 5 | var obj = { 6 | a: "A", 7 | b: "B", 8 | c: "C" 9 | }; 10 | 11 | function func(number) { 12 | return number + 1; 13 | } -------------------------------------------------------------------------------- /test/shared/json5-loader/testfile.json: -------------------------------------------------------------------------------- 1 | { 2 | "foo": "bar", 3 | "while": true, 4 | "this": "is a multi-line string", 5 | "here": "is another", 6 | "hex": 3735928559, 7 | "half": 0.5, 8 | "finally": "a trailing comma", 9 | "oh": [ 10 | "we shouldn't forget", 11 | "arrays can have", 12 | "trailing commas too" 13 | ] 14 | } -------------------------------------------------------------------------------- /test/client/worker-loader/worker.js: -------------------------------------------------------------------------------- 1 | onmessage = function(event) { 2 | require(["./identitiy"], function(identitiy) { 3 | if(module.hot) { 4 | postMessage(null); 5 | } else { 6 | postMessage(identitiy(event.data)); 7 | } 8 | if(typeof __$coverObject !== "undefined") 9 | postMessage(JSON.stringify(__$coverObject)); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /test/client/expose.js: -------------------------------------------------------------------------------- 1 | var should = require("chai/lib/chai").should(); 2 | 3 | describe("expose-loader", function() { 4 | it("should expose a property to the global context", function() { 5 | delete global.property; 6 | delete require.cache[require.resolve("expose?property!./expose-loader/stuff")]; 7 | require("expose?property!./expose-loader/stuff"); 8 | global.property.should.be.eql("ABC"); 9 | delete global.property; 10 | }); 11 | }); -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var BannerPlugin = require("webpack/lib/BannerPlugin"); 2 | module.exports = { 3 | entry: "mocha!./test/client-tests", 4 | output: { 5 | path: "assets", 6 | publicPath: "/assets/" 7 | }, 8 | module: { 9 | loaders: [ 10 | { test: /\.json$/, loader: "json-loader" }, 11 | { test: /\.css$/, loader: "style-loader!css-loader" }, 12 | { test: /\.coffee$/, loader: "coffee-loader" } 13 | ] 14 | }, 15 | plugins: [ 16 | new BannerPlugin("Used for the-big-test\nCreated by @sokra") 17 | ] 18 | } -------------------------------------------------------------------------------- /test/shared/json5-loader/testfile.json5: -------------------------------------------------------------------------------- 1 | { 2 | foo: 'bar', 3 | while: true, 4 | 5 | this: 'is a\ 6 | multi-line string', 7 | 8 | // this is an inline comment 9 | here: 'is another', // inline comment 10 | 11 | /* this is a block comment 12 | that continues on another line */ 13 | 14 | hex: 0xDEADbeef, 15 | half: .5, 16 | 17 | finally: 'a trailing comma', 18 | oh: [ 19 | "we shouldn't forget", 20 | 'arrays can have', 21 | 'trailing commas too', 22 | ], 23 | } -------------------------------------------------------------------------------- /cover-webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: "mocha!./test/cover-client-tests", 3 | output: { 4 | path: "assets", 5 | publicPath: "/assets/" 6 | }, 7 | module: { 8 | loaders: [ 9 | { test: /\.json$/, loader: "json" }, 10 | { test: /\.css$/, loader: "style!css" }, 11 | { test: /\.coffee$/, loader: "coffee-loader" } 12 | ], 13 | postLoaders: [{ 14 | test: /./, // any 15 | exclude: [ 16 | /node_modules.chai/, 17 | /node_modules.mocha-loader/, 18 | /node_modules.coverjs-loader/, 19 | /node_modules.webpack.buildin/, 20 | /node_modules.node-libs-browser/ 21 | ], 22 | loader: "coverjs-loader" 23 | }] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # the big webpack test 2 | 3 | ## Do tests in node.js 4 | 5 | Single run: 6 | 7 | ``` text 8 | node bin/enhanced-require "mocha!./test/server-tests" 9 | ``` 10 | 11 | Watching run: 12 | 13 | ``` text 14 | node bin/enhanced-require-hot-watch "mocha!./test/server-tests" 15 | ``` 16 | 17 | ## Do tests in browser 18 | 19 | ``` text 20 | node bin/webpack-dev-server 21 | ``` 22 | 23 | and navigate your browser to [http://localhost:8080/](http://localhost:8080/). 24 | 25 | ## Cover browser run 26 | 27 | ``` text 28 | node bin/webpack-dev-server --config cover-webpack.config.js 29 | ``` 30 | 31 | and navigate your browser to [http://localhost:8080/](http://localhost:8080/). 32 | -------------------------------------------------------------------------------- /test/client/worker.js: -------------------------------------------------------------------------------- 1 | var should = require("chai/lib/chai").should(); 2 | 3 | describe("worker-loader", function() { 4 | it("should create a valid worker", function(done) { 5 | var MyWorker = require("worker!./worker-loader/worker"); 6 | var worker = new MyWorker(); 7 | worker.postMessage("abc123"); 8 | worker.onmessage = function(event) { 9 | if(typeof __$coverObject !== "undefined" && event.data.indexOf("{") === 0) { 10 | // To cover worker code 11 | // we transfer the coverObject 12 | var workerCover = JSON.parse(event.data); 13 | for(var name in workerCover) 14 | __$coverObject[name] = workerCover[name]; 15 | return; 16 | } 17 | event.data.should.be.eql("abc123"); 18 | done(); 19 | }; 20 | }); 21 | }); -------------------------------------------------------------------------------- /test/shared/json5.js: -------------------------------------------------------------------------------- 1 | var should = require("chai/lib/chai").should(); 2 | 3 | describe("json5-loader", function() { 4 | it("should load a test file", function() { 5 | var testfile = require("json5!./json5-loader/testfile.json5"); 6 | should.exist(testfile); 7 | testfile.should.have.property("foo").be.eql("bar"); 8 | testfile.should.have.property("while").be.eql(true); 9 | testfile.should.have.property("this").be.eql("is a multi-line string"); 10 | testfile.should.have.property("here").be.eql("is another"); 11 | testfile.should.have.property("hex").be.eql(0xDEADbeef); 12 | testfile.should.have.property("half").be.eql(.5); 13 | testfile.should.have.property("finally").be.eql('a trailing comma'); 14 | testfile.should.be.eql(require("./json5-loader/testfile.json")); 15 | }); 16 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "the-big-test", 3 | "version": "0.1.0", 4 | "author": "Tobias Koppers @sokra", 5 | "private": true, 6 | "licenses": [ 7 | { 8 | "type": "MIT", 9 | "url": "http://www.opensource.org/licenses/mit-license.php" 10 | } 11 | ], 12 | "homepage": "http://github.com/webpack/the-big-test", 13 | "dependencies": { 14 | "webpack": "1.x", 15 | "webpack-dev-server": "1.2.x", 16 | "grunt": "~0.4.0", 17 | "grunt-webpack": "1.x", 18 | "chai": "1.4.x", 19 | "enhanced-require": "0.5.x", 20 | "mocha-loader": "0.5.x", 21 | "coverjs-loader": "0.5.x", 22 | "coffee-loader": "0.6.x", 23 | "bundle-loader": "0.5.x", 24 | "imports-loader": "0.6.x", 25 | "exports-loader": "0.6.x", 26 | "expose-loader": "0.5.x", 27 | "worker-loader": "0.5.x", 28 | "json5-loader": "0.5.x", 29 | "json-loader": "0.5.x", 30 | "style-loader": "0.6.x", 31 | "css-loader": "0.6.x" 32 | }, 33 | "scripts": { 34 | "test": "node bin/enhanced-require mocha!./test/server-tests" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/shared/exports.js: -------------------------------------------------------------------------------- 1 | var should = require("chai/lib/chai").should(); 2 | 3 | describe("exports-loader", function() { 4 | it("should export a var", function() { 5 | var exports = require("exports?a!./exports-loader/stuff"); 6 | should.exist(exports); 7 | exports.should.be.eql("a"); 8 | }); 9 | 10 | it("should export some vars", function() { 11 | var exports = require("exports?a,b,c!./exports-loader/stuff"); 12 | should.exist(exports); 13 | exports.should.have.property("a").be.eql("a"); 14 | exports.should.have.property("b").be.eql("b"); 15 | exports.should.have.property("c").be.eql("c"); 16 | }); 17 | 18 | it("should export renamed vars", function() { 19 | var exports = require("exports?a=b,b=c,c=a!./exports-loader/stuff"); 20 | should.exist(exports); 21 | exports.should.have.property("a").be.eql("b"); 22 | exports.should.have.property("b").be.eql("c"); 23 | exports.should.have.property("c").be.eql("a"); 24 | }); 25 | 26 | it("should export stuff from obj", function() { 27 | var exports = require("exports?a=obj.a,b=obj.b,obj=obj!./exports-loader/stuff"); 28 | should.exist(exports); 29 | exports.should.have.property("a").be.eql("A"); 30 | exports.should.have.property("b").be.eql("B"); 31 | exports.should.have.property("obj").be.eql({ 32 | a: "A", 33 | b: "B", 34 | c: "C" 35 | }); 36 | }); 37 | }); -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | var BannerPlugin = require("webpack/lib/BannerPlugin"); 2 | 3 | module.exports = function(grunt) { 4 | grunt.initConfig({ 5 | webpack: { 6 | test: { 7 | entry: "mocha!./test/client-tests", 8 | module: { 9 | loaders: [ 10 | { test: /\.json$/, loader: "<%= 'json' %>" }, 11 | ] 12 | }, 13 | plugins: [ 14 | new BannerPlugin("Used for the-big-test\nCreated by @sokra") 15 | ] 16 | }, 17 | "cover-test": { 18 | entry: "mocha!./test/cover-client-tests", 19 | module: { 20 | loaders: [ 21 | { test: /\.json$/, loader: "json" }, 22 | ], 23 | postLoaders: [{ 24 | test: /./, // any 25 | exclude: [ 26 | /node_modules.chai/, 27 | /node_modules.mocha-loader/, 28 | /node_modules.coverjs-loader/, 29 | /node_modules.webpack.buildin/ 30 | ], 31 | loader: "coverjs-loader" 32 | }] 33 | } 34 | }, 35 | options: { 36 | output: { 37 | path: "assets", 38 | publicPath: "assets/" 39 | }, 40 | module: { 41 | loaders: [ 42 | { test: /\.css$/, loader: "style!css" }, 43 | { test: /\.coffee$/, loader: "coffee-loader" } 44 | ], 45 | }, 46 | plugins: [ 47 | ] 48 | } 49 | } 50 | }); 51 | 52 | grunt.loadNpmTasks('grunt-webpack'); 53 | 54 | grunt.registerTask('default', ['webpack:test']); 55 | grunt.registerTask('cover', ['webpack:cover-test']); 56 | }; 57 | -------------------------------------------------------------------------------- /test/shared/imports.js: -------------------------------------------------------------------------------- 1 | var should = require("chai/lib/chai").should(); 2 | 3 | describe("imports-loader", function() { 4 | it("should import a module", function() { 5 | var importModule = require("imports?moduleA!./imports-loader/import-test-file"); 6 | should.exist(importModule); 7 | importModule.should.be.eql({ module: true }); 8 | }); 9 | 10 | it("should import a coffee-script module", function() { 11 | var importModule = require("imports?moduleA!./imports-loader/import-test-file.coffee"); 12 | should.exist(importModule); 13 | importModule.should.be.eql({ module: true }); 14 | }); 15 | 16 | it("should import a module with text", function() { 17 | var importModule = require("imports?moduleA=moduleB!./imports-loader/import-test-file"); 18 | should.exist(importModule); 19 | importModule.should.be.eql({ moduleB: true }); 20 | }); 21 | 22 | it("should import a file with text", function() { 23 | var importModule = require("imports?moduleA=./file!./imports-loader/import-test-file"); 24 | should.exist(importModule); 25 | importModule.should.be.eql({ file: true }); 26 | }); 27 | 28 | it("should import custom javascript", function() { 29 | var importModule = require("imports?moduleA=>{custom:true}!./imports-loader/import-test-file"); 30 | should.exist(importModule); 31 | importModule.should.be.eql({ custom: true }); 32 | }); 33 | 34 | it("should import multiple stuff", function() { 35 | var importModule = require("imports?moduleA,moduleB=./file,moduleC=>{custom:true}!./imports-loader/import-test-file2"); 36 | should.exist(importModule); 37 | importModule.should.have.property("moduleA").be.eql({ module: true }); 38 | importModule.should.have.property("moduleB").be.eql({ file: true }); 39 | importModule.should.have.property("moduleC").be.eql({ custom: true }); 40 | }); 41 | }); --------------------------------------------------------------------------------