Skip to content

Commit edb55d3

Browse files
committed
test: add test for babel plugin
1 parent b60ab22 commit edb55d3

File tree

10 files changed

+102
-6
lines changed

10 files changed

+102
-6
lines changed

babel-plugin-code-push/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Babel plugin for @bravemobile/react-native-code-push",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest"
7+
"test": "cd test && jest"
88
},
99
"keywords": [],
1010
"author": "",

babel-plugin-code-push/test/.babelrc

-3
This file was deleted.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = function (api) {
2+
if (api.env("test")) {
3+
return {
4+
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
5+
plugins: [["../index.js"]],
6+
};
7+
}
8+
9+
return {
10+
plugins: [["../index.js"]],
11+
};
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const {
2+
SemverVersioning,
3+
} = require("@bravemobile/react-native-code-push/versioning");
4+
5+
class CustomVersioning extends SemverVersioning {
6+
constructor() {
7+
super();
8+
}
9+
}
10+
11+
module.exports = {
12+
bundleHost: "bundleHost",
13+
runtimeVersion: "runtimeVersion",
14+
versioning: CustomVersioning,
15+
updateChecker: (updateRequest) => {
16+
// ..my Implementation
17+
},
18+
};

babel-plugin-code-push/test/outputFile.js renamed to babel-plugin-code-push/test/cases/test1-output

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SemverVersioning } from "@bravemobile/react-native-code-push/versioning/SemverVersioning.js";
1+
import { SemverVersioning } from "@bravemobile/react-native-code-push/versioning";
22
import codePush from "@bravemobile/react-native-code-push";
33
codePush({
44
bundleHost: "bundleHost",
@@ -11,4 +11,4 @@ codePush({
1111
updateChecker: updateRequest => {
1212
// ..my Implementation
1313
}
14-
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const {
2+
SemverVersioning,
3+
} = require("@bravemobile/react-native-code-push/versioning");
4+
5+
module.exports = {
6+
bundleHost: "bundleHost",
7+
runtimeVersion: "runtimeVersion",
8+
versioning: SemverVersioning,
9+
updateChecker: (updateRequest) => {
10+
// ..my Implementation
11+
},
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import codePush from "@bravemobile/react-native-code-push";
2+
3+
codePush();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { SemverVersioning } from "@bravemobile/react-native-code-push/versioning";
2+
import codePush from "@bravemobile/react-native-code-push";
3+
codePush({
4+
bundleHost: "bundleHost",
5+
runtimeVersion: "runtimeVersion",
6+
versioning: SemverVersioning,
7+
updateChecker: updateRequest => {
8+
// ..my Implementation
9+
}
10+
});
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import fs from "fs";
2+
import { transformSync } from "@babel/core";
3+
4+
describe("babel plugin", () => {
5+
test("case1: using custom Versioning class", () => {
6+
const input = fs.readFileSync("./cases/test1-input", { encoding: "utf-8" });
7+
const expected = fs.readFileSync("./cases/test1-output", {
8+
encoding: "utf-8",
9+
});
10+
11+
const generated = transformSync(input, {
12+
plugins: [
13+
[
14+
"../index.js",
15+
{
16+
configPath: "./cases/test1-config",
17+
},
18+
],
19+
],
20+
});
21+
22+
expect(generated.code).toBe(expected);
23+
});
24+
25+
test("case2: using provided Versioning class", () => {
26+
const input = fs.readFileSync("./cases/test2-input", { encoding: "utf-8" });
27+
const expected = fs.readFileSync("./cases/test2-output", {
28+
encoding: "utf-8",
29+
});
30+
31+
const generated = transformSync(input, {
32+
plugins: [
33+
[
34+
"../index.js",
35+
{
36+
configPath: "./cases/test2-config",
37+
},
38+
],
39+
],
40+
});
41+
42+
expect(generated.code).toBe(expected);
43+
});
44+
});

0 commit comments

Comments
 (0)