test all configCases with persistent cache
This commit is contained in:
parent
264aa3a5c8
commit
aa210c4aed
|
@ -0,0 +1,10 @@
|
|||
const path = require("path");
|
||||
const { describeCases } = require("./ConfigTestCases.template");
|
||||
|
||||
describeCases({
|
||||
name: "ConfigCacheTestCases",
|
||||
cache: {
|
||||
type: "filesystem",
|
||||
managedPaths: [path.resolve(__dirname, "../node_modules")]
|
||||
}
|
||||
});
|
|
@ -42,6 +42,7 @@ const describeCases = config => {
|
|||
const outBaseDir = path.join(__dirname, "js");
|
||||
const testSubPath = path.join(config.name, category.name, testName);
|
||||
const outputDirectory = path.join(outBaseDir, testSubPath);
|
||||
const cacheDirectory = path.join(outBaseDir, ".cache", testSubPath);
|
||||
let options, optionsArr, testConfig;
|
||||
beforeAll(() => {
|
||||
options = prepareOptions(
|
||||
|
@ -63,6 +64,13 @@ const describeCases = config => {
|
|||
options.output.pathinfo = true;
|
||||
if (!options.output.filename)
|
||||
options.output.filename = "bundle" + idx + ".js";
|
||||
if (config.cache) {
|
||||
options.cache = {
|
||||
cacheDirectory,
|
||||
name: `config-${idx}`,
|
||||
...config.cache
|
||||
};
|
||||
}
|
||||
});
|
||||
testConfig = {
|
||||
findBundle: function (i, options) {
|
||||
|
@ -88,34 +96,62 @@ const describeCases = config => {
|
|||
}
|
||||
if (testConfig.timeout) setDefaultTimeout(testConfig.timeout);
|
||||
});
|
||||
beforeAll(() => {
|
||||
rimraf.sync(cacheDirectory);
|
||||
});
|
||||
const handleFatalError = (err, done) => {
|
||||
const fakeStats = {
|
||||
errors: [
|
||||
{
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
]
|
||||
};
|
||||
if (
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
fakeStats,
|
||||
"error",
|
||||
"Error",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
// Wait for uncaught errors to occur
|
||||
setTimeout(done, 200);
|
||||
return;
|
||||
};
|
||||
if (config.cache) {
|
||||
it(`${testName} should pre-compile to fill disk cache (1st)`, done => {
|
||||
rimraf.sync(outputDirectory);
|
||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||
const deprecationTracker = deprecationTracking.start();
|
||||
webpack(options, err => {
|
||||
deprecationTracker();
|
||||
if (err) return handleFatalError(err, done);
|
||||
done();
|
||||
});
|
||||
}, 60000);
|
||||
it(`${testName} should pre-compile to fill disk cache (2nd)`, done => {
|
||||
rimraf.sync(outputDirectory);
|
||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||
const deprecationTracker = deprecationTracking.start();
|
||||
webpack(options, err => {
|
||||
deprecationTracker();
|
||||
if (err) return handleFatalError(err, done);
|
||||
done();
|
||||
});
|
||||
}, 20000);
|
||||
}
|
||||
it(`${testName} should compile`, done => {
|
||||
rimraf.sync(outputDirectory);
|
||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||
const deprecationTracker = deprecationTracking.start();
|
||||
webpack(options, (err, stats) => {
|
||||
if (err) {
|
||||
const fakeStats = {
|
||||
errors: [
|
||||
{
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
]
|
||||
};
|
||||
if (
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
fakeStats,
|
||||
"error",
|
||||
"Error",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
// Wait for uncaught errors to occur
|
||||
return setTimeout(done, 200);
|
||||
}
|
||||
const deprecations = deprecationTracker();
|
||||
if (err) return handleFatalError(err, done);
|
||||
const statOptions = {
|
||||
preset: "verbose",
|
||||
colors: false
|
||||
|
@ -156,7 +192,6 @@ const describeCases = config => {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
const deprecations = deprecationTracker();
|
||||
if (
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ConfigCacheTestCases custom-modules json-custom exported tests should transform toml to json 1`] = `
|
||||
Object {
|
||||
"owner": Object {
|
||||
"bio": "GitHub Cofounder & CEO
|
||||
Likes tater tots and beer.",
|
||||
"dob": "1979-05-27T07:32:00.000Z",
|
||||
"name": "Tom Preston-Werner",
|
||||
"organization": "GitHub",
|
||||
},
|
||||
"title": "TOML Example",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`ConfigCacheTestCases records issue-2991 exported tests should write relative paths to records 1`] = `
|
||||
"{
|
||||
\\"chunks\\": {
|
||||
\\"byName\\": {
|
||||
\\"main\\": 179
|
||||
},
|
||||
\\"bySource\\": {
|
||||
\\"0 main\\": 179
|
||||
},
|
||||
\\"usedIds\\": [
|
||||
179
|
||||
]
|
||||
},
|
||||
\\"modules\\": {
|
||||
\\"byIdentifier\\": {
|
||||
\\"./test.js\\": 393,
|
||||
\\"external \\\\\\"fs\\\\\\"\\": 747,
|
||||
\\"external \\\\\\"path\\\\\\"\\": 622,
|
||||
\\"ignored|pkgs/somepackage/foo\\": 713
|
||||
},
|
||||
\\"usedIds\\": [
|
||||
393,
|
||||
622,
|
||||
713,
|
||||
747
|
||||
]
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`ConfigCacheTestCases records issue-7339 exported tests should write relative dynamic-require paths to records 1`] = `
|
||||
"{
|
||||
\\"chunks\\": {
|
||||
\\"byName\\": {
|
||||
\\"main\\": 179
|
||||
},
|
||||
\\"bySource\\": {
|
||||
\\"0 main\\": 179
|
||||
},
|
||||
\\"usedIds\\": [
|
||||
179
|
||||
]
|
||||
},
|
||||
\\"modules\\": {
|
||||
\\"byIdentifier\\": {
|
||||
\\"./dependencies/bar.js\\": 379,
|
||||
\\"./dependencies/foo.js\\": 117,
|
||||
\\"./dependencies|sync|/^\\\\\\\\.\\\\\\\\/.*$/\\": 412,
|
||||
\\"./test.js\\": 393,
|
||||
\\"external \\\\\\"fs\\\\\\"\\": 747,
|
||||
\\"external \\\\\\"path\\\\\\"\\": 622
|
||||
},
|
||||
\\"usedIds\\": [
|
||||
117,
|
||||
379,
|
||||
393,
|
||||
412,
|
||||
622,
|
||||
747
|
||||
]
|
||||
}
|
||||
}"
|
||||
`;
|
Loading…
Reference in New Issue