Skip to content

Commit e7a671f

Browse files
committed
fix a few more expects and make the test output paths more sturdy
1 parent b2c54f1 commit e7a671f

11 files changed

Lines changed: 39 additions & 39 deletions

File tree

‎test/Examples.test.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ describe("Examples", () => {
1111

1212
examples.forEach((examplePath) => {
1313
const filterPath = path.join(examplePath, "test.filter.js");
14+
const relativePath = path.relative(basePath, examplePath);
1415
if(fs.existsSync(filterPath) && !require(filterPath)()) {
15-
describe.skip(path.relative(basePath, examplePath), () => it("filtered"));
16+
describe.skip(relativePath, () => it("filtered"));
1617
return;
1718
}
18-
it("should compile " + path.relative(basePath, examplePath), function(done) {
19-
jest.setTimeout(20000);
19+
it("should compile " + relativePath, function(done) {
2020
let options = {};
2121
let webpackConfigPath = path.join(examplePath, "webpack.config.js");
2222
webpackConfigPath = webpackConfigPath.substr(0, 1).toUpperCase() + webpackConfigPath.substr(1);
@@ -53,6 +53,6 @@ describe("Examples", () => {
5353
}
5454
done();
5555
});
56-
});
56+
}, 20000);
5757
});
5858
});

‎test/HotModuleReplacementPlugin.test.js‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
const path = require("path");
44
const fs = require("fs");
5+
const mkdirp = require("mkdirp");
56

67
const webpack = require("../");
78

89
describe("HotModuleReplacementPlugin", () => {
910
jest.setTimeout(10000);
1011
it("should not have circular hashes but equal if unmodified", (done) => {
11-
const entryFile = path.join(__dirname, "js", "entry.js");
12-
const statsFile1 = path.join(__dirname, "js", "HotModuleReplacementPlugin.test.stats1.txt");
13-
const statsFile2 = path.join(__dirname, "js", "HotModuleReplacementPlugin.test.stats2.txt");
14-
const recordsFile = path.join(__dirname, "js", "records.json");
12+
const entryFile = path.join(__dirname, "js", "HotModuleReplacementPlugin", "entry.js");
13+
const statsFile1 = path.join(__dirname, "js", "HotModuleReplacementPlugin", "HotModuleReplacementPlugin.test.stats1.txt");
14+
const statsFile2 = path.join(__dirname, "js", "HotModuleReplacementPlugin", "HotModuleReplacementPlugin.test.stats2.txt");
15+
const recordsFile = path.join(__dirname, "js", "HotModuleReplacementPlugin", "records.json");
1516
try {
16-
fs.mkdirSync(path.join(__dirname, "js"));
17+
mkdirp.sync(path.join(__dirname, "js", "HotModuleReplacementPlugin"));
1718
} catch(e) {}
1819
try {
1920
fs.unlinkSync(recordsFile);
@@ -23,7 +24,7 @@ describe("HotModuleReplacementPlugin", () => {
2324
entry: entryFile,
2425
recordsPath: recordsFile,
2526
output: {
26-
path: path.join(__dirname, "js")
27+
path: path.join(__dirname, "js", "HotModuleReplacementPlugin")
2728
},
2829
plugins: [
2930
new webpack.HotModuleReplacementPlugin(),

‎test/NodeTemplatePlugin.test.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("NodeTemplatePlugin", () => {
1212
context: path.join(__dirname, "fixtures", "nodetest"),
1313
target: "node",
1414
output: {
15-
path: path.join(__dirname, "js"),
15+
path: path.join(__dirname, "js", "NodeTemplatePlugin"),
1616
filename: "result.js",
1717
chunkFilename: "[hash].result.[id].js",
1818
library: "abc",
@@ -24,7 +24,7 @@ describe("NodeTemplatePlugin", () => {
2424
expect(stats.hasErrors()).toBe(false);
2525
expect(stats.hasWarnings()).toBe(false);
2626
// eslint-disable-next-line node/no-missing-require
27-
const result = require("./js/result").abc;
27+
const result = require("./js/NodeTemplatePlugin/result").abc;
2828
expect(result.nextTick).toBe(process.nextTick);
2929
expect(result.fs).toBe(require("fs"));
3030
result.loadChunk(456, (chunk) => {
@@ -45,7 +45,7 @@ describe("NodeTemplatePlugin", () => {
4545
context: path.join(__dirname, "fixtures", "nodetest"),
4646
target: "node",
4747
output: {
48-
path: path.join(__dirname, "js"),
48+
path: path.join(__dirname, "js", "NodeTemplatePluginSingle"),
4949
filename: "result2.js",
5050
chunkFilename: "[hash].result2.[id].js",
5151
library: "def",
@@ -62,7 +62,7 @@ describe("NodeTemplatePlugin", () => {
6262
if(err) return err;
6363
expect(stats.hasErrors()).toBe(false);
6464
// eslint-disable-next-line node/no-missing-require
65-
const result = require("./js/result2");
65+
const result = require("./js/NodeTemplatePluginSingle/result2");
6666
expect(result.nextTick).toBe(process.nextTick);
6767
expect(result.fs).toBe(require("fs"));
6868
const sameTick = true;

‎test/cases/json/import-with-default/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import e from "../data/e.json";
66
import f from "../data/f.json";
77

88
it("should be possible to import json data", function() {
9-
({a}expect()).toEqual({a: null});
9+
expect({a}).toEqual({a: null});
1010
expect(b).toBe(123);
1111
expect(c).toEqual([1, 2, 3, 4]);
1212
expect(d).toEqual({});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
it("should handle the jade loader correctly", function() {
2-
require("!jade-loader?self!../_resources/template.jade")({abc: "abc"}expect()).toBe("<p>selfabc</p><h1>included</h1>");
3-
require("../_resources/template.jade")({abc: "abc"}expect()).toBe("<p>abc</p><h1>included</h1>");
2+
expect(require("!jade-loader?self!../_resources/template.jade")({ abc: "abc" })).toBe("<p>selfabc</p><h1>included</h1>");
3+
expect(require("../_resources/template.jade")({ abc: "abc" })).toBe("<p>abc</p><h1>included</h1>");
44
});

‎test/cases/mjs/cjs-import-default/index.mjs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { ns, default as def1, def as def2, data as data2 } from "./reexport.mjs"
55
import * as reexport from "./reexport.mjs";
66

77
it("should get correct values when importing named exports from a CommonJs module from mjs", function() {
8-
expect((typeof data)).toBe("undefined");
9-
({ data }expect()).toEqual({ data: undefined });
8+
expect(typeof data).toBe("undefined");
9+
expect({ data }).toEqual({ data: undefined });
1010
expect(def).toEqual({
1111
data: "ok",
1212
default: "default"
1313
});
14-
({ def }expect()).toEqual({
14+
expect({ def }).toEqual({
1515
def: {
1616
data: "ok",
1717
default: "default"
@@ -24,7 +24,7 @@ it("should get correct values when importing named exports from a CommonJs modul
2424
default: "default"
2525
}
2626
});
27-
({ star }expect()).toEqual({
27+
expect({ star }).toEqual({
2828
star: {
2929
default: {
3030
data: "ok",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {x, f} from "./x";
22

33
it("should import into object literal", function() {
4-
({ x: x }expect()).toEqual({x: 1});
4+
(expect({ x: x })).toEqual({x: 1});
55
var obj = { x: x };
66
expect(obj).toEqual({x: 1});
77
});
@@ -13,8 +13,8 @@ function func(z) {
1313
it("should import into function argument", function() {
1414
expect(func(x)).toBe(1);
1515
expect(f(x)).toBe(1);
16-
func({x:x}expect()).toEqual({x:1});
17-
f({x:x}expect()).toEqual({x:1});
16+
expect(func({x:x})).toEqual({x:1});
17+
expect(f({x:x})).toEqual({x:1});
1818
var y = f(x);
1919
expect(y).toBe(1);
2020
y = function() {
@@ -24,8 +24,8 @@ it("should import into function argument", function() {
2424
});
2525

2626
it("should import into array literal", function() {
27-
expect(([x, f(2)])).toEqual([1, 2]);
28-
([{
27+
expect([x, f(2)]).toEqual([1, 2]);
28+
expect([{
2929
value: x
30-
}expect(])).toEqual([{ value: x }]);
30+
}]).toEqual([{ value: x }]);
3131
});

‎test/cases/runtime/error-handling/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function testCase(number) {
22
expect(require(number === 1 ? "./folder/file1" : number === 2 ? "./folder/file2" : number === 3 ? "./folder/file3" : "./missingModule")).toBe("file" + number);
3-
require(
3+
expect(require(
44
number === 1 ? "./folder/file1" :
55
number === 2 ? "./folder/file2" :
66
number === 3 ? "./folder/file3" :
77
"./missingModule"
8-
expect()).toBe("file" + number);
8+
)).toBe("file" + number);
99
}
1010

1111

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
it("should have __webpack_hash__", function() {
2-
expect(typeof __webpack_hash__).toBeTypeOf("string");
2+
expect(__webpack_hash__).toBeTypeOf("string");
33
expect(__webpack_hash__).toMatch(/^[0-9a-f]{20}$/);
44
});
55
it("should have __webpack_chunkname__", function() {
6-
expect(typeof __webpack_chunkname__).toBeTypeOf("string");
7-
expect(__webpack_chunkname__).toBe('other');
6+
expect(__webpack_chunkname__).toBeTypeOf("string");
7+
expect(__webpack_chunkname__).toBe("other");
88
});

‎test/configCases/plugins/profiling-plugin/index.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ it("should generate a events.json file", () => {
22
var fs = require("fs"),
33
path = require("path"),
44
os = require("os");
5-
expect(fs.existsSync(path.join(os.tmpdir(), "events.json"))).toBe(true);
5+
expect(fs.existsSync(path.join(__dirname, "events.json"))).toBe(true);
66
});
77

88
it("should have proper setup record inside of the json stream", () => {
@@ -11,6 +11,6 @@ it("should have proper setup record inside of the json stream", () => {
1111
os = require("os");
1212

1313
// convert json stream to valid
14-
var source = JSON.parse(fs.readFileSync(path.join(os.tmpdir(), "events.json"), "utf-8").toString() + "{}]");
14+
var source = JSON.parse(fs.readFileSync(path.join(__dirname, "events.json"), "utf-8").toString() + "{}]");
1515
expect(source[0].id).toEqual(1);
16-
});
16+
});

0 commit comments

Comments
 (0)