Skip to content

Commit eb168d5

Browse files
committed
reformat HotTestCases
adds braces webpack#6565 (comment) also run prettier on the file
1 parent bb51d3b commit eb168d5

1 file changed

Lines changed: 162 additions & 139 deletions

File tree

test/HotTestCases.test.js

Lines changed: 162 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -24,154 +24,177 @@ describe("HotTestCases", () => {
2424
categories.forEach(category => {
2525
describe(category.name, () => {
2626
category.tests.forEach(testName => {
27-
describe(testName, () => {
28-
let exportedTests = [];
29-
it(testName + " should compile", done => {
30-
const testDirectory = path.join(casesPath, category.name, testName);
31-
const outputDirectory = path.join(
32-
__dirname,
33-
"js",
34-
"hot-cases",
35-
category.name,
36-
testName
37-
);
38-
const recordsPath = path.join(outputDirectory, "records.json");
39-
if (fs.existsSync(recordsPath)) fs.unlinkSync(recordsPath);
40-
const fakeUpdateLoaderOptions = {
41-
updateIndex: 0
42-
};
43-
const configPath = path.join(testDirectory, "webpack.config.js");
44-
let options = {};
45-
if (fs.existsSync(configPath)) options = require(configPath);
46-
if (!options.mode) options.mode = "development";
47-
if (!options.context) options.context = testDirectory;
48-
if (!options.entry) options.entry = "./index.js";
49-
if (!options.output) options.output = {};
50-
if (!options.output.path) options.output.path = outputDirectory;
51-
if (!options.output.filename) options.output.filename = "bundle.js";
52-
if (options.output.pathinfo === undefined)
53-
options.output.pathinfo = true;
54-
if (!options.module) options.module = {};
55-
if (!options.module.rules) options.module.rules = [];
56-
options.module.rules.push({
57-
test: /\.js$/,
58-
loader: path.join(__dirname, "hotCases", "fake-update-loader.js"),
59-
enforce: "pre"
60-
});
61-
if (!options.target) options.target = "async-node";
62-
if (!options.plugins) options.plugins = [];
63-
options.plugins.push(
64-
new webpack.HotModuleReplacementPlugin(),
65-
new webpack.NamedModulesPlugin(),
66-
new webpack.LoaderOptionsPlugin(fakeUpdateLoaderOptions)
67-
);
68-
if (!options.recordsPath) options.recordsPath = recordsPath;
69-
const compiler = webpack(options);
70-
compiler.run((err, stats) => {
71-
if (err) return done(err);
72-
const jsonStats = stats.toJson({
73-
errorDetails: true
27+
describe(
28+
testName,
29+
() => {
30+
let exportedTests = [];
31+
it(testName + " should compile", done => {
32+
const testDirectory = path.join(
33+
casesPath,
34+
category.name,
35+
testName
36+
);
37+
const outputDirectory = path.join(
38+
__dirname,
39+
"js",
40+
"hot-cases",
41+
category.name,
42+
testName
43+
);
44+
const recordsPath = path.join(outputDirectory, "records.json");
45+
if (fs.existsSync(recordsPath)) fs.unlinkSync(recordsPath);
46+
const fakeUpdateLoaderOptions = {
47+
updateIndex: 0
48+
};
49+
const configPath = path.join(testDirectory, "webpack.config.js");
50+
let options = {};
51+
if (fs.existsSync(configPath)) options = require(configPath);
52+
if (!options.mode) options.mode = "development";
53+
if (!options.context) options.context = testDirectory;
54+
if (!options.entry) options.entry = "./index.js";
55+
if (!options.output) options.output = {};
56+
if (!options.output.path) options.output.path = outputDirectory;
57+
if (!options.output.filename)
58+
options.output.filename = "bundle.js";
59+
if (options.output.pathinfo === undefined)
60+
options.output.pathinfo = true;
61+
if (!options.module) options.module = {};
62+
if (!options.module.rules) options.module.rules = [];
63+
options.module.rules.push({
64+
test: /\.js$/,
65+
loader: path.join(
66+
__dirname,
67+
"hotCases",
68+
"fake-update-loader.js"
69+
),
70+
enforce: "pre"
7471
});
75-
if (
76-
checkArrayExpectation(
77-
testDirectory,
78-
jsonStats,
79-
"error",
80-
"Error",
81-
done
82-
)
83-
)
84-
return;
85-
if (
86-
checkArrayExpectation(
87-
testDirectory,
88-
jsonStats,
89-
"warning",
90-
"Warning",
91-
done
92-
)
93-
)
94-
return;
72+
if (!options.target) options.target = "async-node";
73+
if (!options.plugins) options.plugins = [];
74+
options.plugins.push(
75+
new webpack.HotModuleReplacementPlugin(),
76+
new webpack.NamedModulesPlugin(),
77+
new webpack.LoaderOptionsPlugin(fakeUpdateLoaderOptions)
78+
);
79+
if (!options.recordsPath) options.recordsPath = recordsPath;
80+
const compiler = webpack(options);
81+
compiler.run((err, stats) => {
82+
if (err) return done(err);
83+
const jsonStats = stats.toJson({
84+
errorDetails: true
85+
});
86+
if (
87+
checkArrayExpectation(
88+
testDirectory,
89+
jsonStats,
90+
"error",
91+
"Error",
92+
done
93+
)
94+
) {
95+
return;
96+
}
97+
if (
98+
checkArrayExpectation(
99+
testDirectory,
100+
jsonStats,
101+
"warning",
102+
"Warning",
103+
done
104+
)
105+
) {
106+
return;
107+
}
95108

96-
function _it(title, fn) {
97-
exportedTests.push({ title, fn, timeout: 5000 });
98-
}
109+
function _it(title, fn) {
110+
exportedTests.push({ title, fn, timeout: 5000 });
111+
}
99112

100-
function _next(callback) {
101-
fakeUpdateLoaderOptions.updateIndex++;
102-
compiler.run((err, stats) => {
103-
if (err) return done(err);
104-
const jsonStats = stats.toJson({
105-
errorDetails: true
113+
function _next(callback) {
114+
fakeUpdateLoaderOptions.updateIndex++;
115+
compiler.run((err, stats) => {
116+
if (err) return done(err);
117+
const jsonStats = stats.toJson({
118+
errorDetails: true
119+
});
120+
if (
121+
checkArrayExpectation(
122+
testDirectory,
123+
jsonStats,
124+
"error",
125+
"errors" + fakeUpdateLoaderOptions.updateIndex,
126+
"Error",
127+
done
128+
)
129+
) {
130+
return;
131+
}
132+
if (
133+
checkArrayExpectation(
134+
testDirectory,
135+
jsonStats,
136+
"warning",
137+
"warnings" + fakeUpdateLoaderOptions.updateIndex,
138+
"Warning",
139+
done
140+
)
141+
) {
142+
return;
143+
}
144+
if (callback) callback(jsonStats);
106145
});
107-
if (
108-
checkArrayExpectation(
109-
testDirectory,
110-
jsonStats,
111-
"error",
112-
"errors" + fakeUpdateLoaderOptions.updateIndex,
113-
"Error",
114-
done
115-
)
116-
)
117-
return;
118-
if (
119-
checkArrayExpectation(
120-
testDirectory,
121-
jsonStats,
122-
"warning",
123-
"warnings" + fakeUpdateLoaderOptions.updateIndex,
124-
"Warning",
125-
done
126-
)
127-
)
128-
return;
129-
if (callback) callback(jsonStats);
130-
});
131-
}
146+
}
132147

133-
function _require(module) {
134-
if (module.substr(0, 2) === "./") {
135-
const p = path.join(outputDirectory, module);
136-
const fn = vm.runInThisContext(
137-
"(function(require, module, exports, __dirname, __filename, it, expect, NEXT, STATS) {" +
138-
"global.expect = expect;" +
139-
fs.readFileSync(p, "utf-8") +
140-
"\n})",
141-
p
142-
);
143-
const m = {
144-
exports: {}
145-
};
146-
fn.call(
147-
m.exports,
148-
_require,
149-
m,
150-
m.exports,
151-
outputDirectory,
152-
p,
153-
_it,
154-
expect,
155-
_next,
156-
jsonStats
148+
function _require(module) {
149+
if (module.substr(0, 2) === "./") {
150+
const p = path.join(outputDirectory, module);
151+
const fn = vm.runInThisContext(
152+
"(function(require, module, exports, __dirname, __filename, it, expect, NEXT, STATS) {" +
153+
"global.expect = expect;" +
154+
fs.readFileSync(p, "utf-8") +
155+
"\n})",
156+
p
157+
);
158+
const m = {
159+
exports: {}
160+
};
161+
fn.call(
162+
m.exports,
163+
_require,
164+
m,
165+
m.exports,
166+
outputDirectory,
167+
p,
168+
_it,
169+
expect,
170+
_next,
171+
jsonStats
172+
);
173+
return m.exports;
174+
} else return require(module);
175+
}
176+
_require("./bundle.js");
177+
if (exportedTests.length < 1)
178+
return done(new Error("No tests exported by test case"));
179+
180+
const asyncSuite = describe("exported tests", () => {
181+
exportedTests.forEach(
182+
({ title, fn, timeout }) =>
183+
fn
184+
? fit(title, fn, timeout)
185+
: fit(title, () => {}).pend("Skipped")
157186
);
158-
return m.exports;
159-
} else return require(module);
160-
}
161-
_require("./bundle.js");
162-
if (exportedTests.length < 1)
163-
return done(new Error("No tests exported by test case"));
187+
});
164188

165-
describe("exported tests", () => {
166-
exportedTests.forEach(
167-
({ title, fn, timeout }) =>
168-
fn ? it(title, fn, timeout) : it.skip(title, () => {})
169-
);
170-
done();
189+
jasmine
190+
.getEnv()
191+
.execute([asyncSuite.id], asyncSuite)
192+
.then(done, done);
171193
});
172194
});
173-
});
174-
}, 10000);
195+
},
196+
10000
197+
);
175198
});
176199
});
177200
});

0 commit comments

Comments
 (0)