Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bundlers.webpack.test.js « test - github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53785de9fd6b88ab6ce3be0879eca5a572aeef8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var vm = require("vm"),
    fs = require("fs"),
    expect = require("expect.js"),
    webpack = require("webpack"),
    configureWebpack = require("../lib/bundlers/webpack/configureWebpack.js");

/**
 * Executes the source in a context that pretends to be a browser
 * @param {!String} src
 */
function runInFakeBrowserContext(src, filename) {
    var context =  {
        describe: describe,
        it: it,
        before: before,
        after: after,
        beforeEach: beforeEach,
        afterEach: afterEach,
        setTimeout: setTimeout,
        clearTimeout: clearTimeout,
        setInterval: setInterval,
        clearInterval: clearInterval,
        parseFloat: parseFloat,
        parseInt: parseInt,
        encodeURIComponent: function () {},
        decodeURIComponent: function () {},
        document: {},
        console: console
    };
    context.window = context;
    vm.runInNewContext(src, context, filename);
}

describe("rewire bundled with webpack", function () {
    before(require("./testHelpers/createFakePackageJSON.js"));
    after(require("./testHelpers/removeFakePackageJSON.js"));
    it("should run all sharedTestCases without exception", function (done) {
        done(); return;
        var webpackOptions,
            src,
            outputPath =  __dirname + "/bundlers/webpack/bundle.js",
            browserBundle;

        webpackOptions = {
            output: outputPath,
            includeFilenames: true,
            debug: true
        };
        configureWebpack(webpackOptions);

        webpack(__dirname + "/testModules/sharedTestCases.js", webpackOptions, function onWebpackFinished(err, stats) {

            expect(err).to.be(null);
            expect(stats.errors).to.have.length(0);
            //expect(stats.warnings).to.have.length(0);

            // Read generated source
            src = fs.readFileSync(outputPath, "utf8");

            // Setup for mocha
            browserBundle = "function enableTests() { " + src + " }";

            // Output for browser-testing
            fs.writeFileSync(outputPath, browserBundle, "utf8");

            // This should throw no exception.
            runInFakeBrowserContext(src, outputPath);

            done();
        });
    });
});