Content-Length: 435851 | pFad | http://github.com/NativeScript/nativescript-cli/commit/6592819433d34cbce113c10bbd40a0cc14fdde2c

DE fix: add unit tests for `bundleValidatorHelper` · NativeScript/nativescript-cli@6592819 · GitHub
Skip to content

Commit 6592819

Browse files
committed
fix: add unit tests for bundleValidatorHelper
1 parent 2c7bafb commit 6592819

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { Yok } from "../../lib/common/yok";
2+
import { BundleValidatorHelper } from "../../lib/helpers/bundle-validator-helper";
3+
import { assert } from "chai";
4+
import { format } from "util";
5+
import { BundleValidatorMessages } from "../../lib/constants";
6+
7+
interface ITestCase {
8+
name: string;
9+
isDependency?: boolean;
10+
currentWebpackVersion?: string;
11+
minSupportedWebpackVersion?: string;
12+
expectedError?: string;
13+
}
14+
15+
let error: string = null;
16+
17+
function createTestInjector(options: { dependencies?: IStringDictionary, devDependencies?: IStringDictionary }) {
18+
const testInjector = new Yok();
19+
testInjector.register("projectData", {
20+
initializeProjectData: () => ({}),
21+
dependencies: options.dependencies,
22+
devDependencies: options.devDependencies
23+
});
24+
testInjector.register("errors", {
25+
fail: (err: string) => error = err
26+
});
27+
testInjector.register("options", ({ bundle: "webpack" }));
28+
testInjector.register("bundleValidatorHelper", BundleValidatorHelper);
29+
30+
return testInjector;
31+
}
32+
33+
describe.only("BundleValidatorHelper", () => {
34+
beforeEach(() => error = null);
35+
36+
let testCases: ITestCase[] = [
37+
{
38+
name: "should throw an error when no webpack plugin is installed",
39+
expectedError: BundleValidatorMessages.MissingBundlePlugin
40+
}
41+
];
42+
43+
["dependencies", "devDependencies"]
44+
.forEach(key => {
45+
const isDependency = key === "dependencies";
46+
47+
testCases = testCases.concat([
48+
{
49+
name: `should not throw an error when webpack is added as ${key}`,
50+
isDependency,
51+
currentWebpackVersion: "0.12.0",
52+
expectedError: null
53+
},
54+
{
55+
name: `should not throw an error when webpack's version is grather than minSupportedVersion in case when webpack is installed as ${key}`,
56+
isDependency,
57+
currentWebpackVersion: "0.13.1",
58+
minSupportedWebpackVersion: "0.13.0",
59+
expectedError: null
60+
},
61+
{
62+
name: `should not throw an error when webpack's version is equal to minSupportedVersion in case when webpack is installed as ${key}`,
63+
isDependency,
64+
currentWebpackVersion: "0.10.0",
65+
minSupportedWebpackVersion: "0.10.0",
66+
expectedError: null
67+
},
68+
{
69+
name: `should throw an error when webpack's version is lower than minSupportedVersion in case when webpack is installed as ${key}`,
70+
isDependency,
71+
currentWebpackVersion: "0.17.0",
72+
minSupportedWebpackVersion: "0.18.0",
73+
expectedError: format(BundleValidatorMessages.NotSupportedVersion, "0.18.0")
74+
}
75+
]);
76+
});
77+
78+
_.each(testCases, (testCase: any) => {
79+
const deps = {
80+
"nativescript-dev-webpack": testCase.currentWebpackVersion
81+
};
82+
83+
it(`${testCase.name}`, async () => {
84+
const injector = createTestInjector({ dependencies: testCase.isDependency ? deps : null, devDependencies: !testCase.isDependency ? deps : null });
85+
const bundleValidatorHelper = injector.resolve("bundleValidatorHelper");
86+
bundleValidatorHelper.validate(testCase.minSupportedWebpackVersion);
87+
88+
assert.deepEqual(error, testCase.expectedError);
89+
});
90+
});
91+
});

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/nativescript-cli/commit/6592819433d34cbce113c10bbd40a0cc14fdde2c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy