Skip to content

Commit 3e2b798

Browse files
author
Christopher J. Brody
committed
test bogus values of platforms with mocking
in CLI command func
1 parent 9cf6e9e commit 3e2b798

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`create alice-bobbi module with logging, with platforms: 'bogus' 1`] = `
4+
Array [
5+
Object {
6+
"warn": Array [
7+
"While \`{DEFAULT_PACKAGE_IDENTIFIER}\` is the default package
8+
identifier, it is recommended to customize the package identifier.",
9+
],
10+
},
11+
Object {
12+
"info": Array [
13+
"CREATE new React Native module with the following options:
14+
15+
root moduleName: react-native-alice-bobbi
16+
name: alice-bobbi
17+
prefix:
18+
modulePrefix: react-native
19+
packageIdentifier: com.reactlibrary
20+
platforms: bogus
21+
githubAccount: github_account
22+
authorName: Your Name
23+
authorEmail: yourname@email.com
24+
authorEmail: yourname@email.com
25+
license: MIT
26+
view: false
27+
useCocoapods: false
28+
generateExample: false
29+
exampleName: example
30+
",
31+
],
32+
},
33+
Object {
34+
"info": Array [
35+
"CREATE: Generating the React Native library module",
36+
],
37+
},
38+
Object {
39+
"ensureDir": "react-native-alice-bobbi",
40+
},
41+
]
42+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const func = require('../../../../../../../../lib/cli-command.js').func;
2+
3+
// special compact mocks for this test:
4+
const mysnap = [];
5+
const mockpushit = x => mysnap.push(x);
6+
jest.mock('fs-extra', () => ({
7+
outputFile: (outputFileName, theContent) => {
8+
mockpushit({ outputFileName, theContent });
9+
return Promise.resolve();
10+
},
11+
ensureDir: (dir) => {
12+
mockpushit({ ensureDir: dir });
13+
return Promise.resolve();
14+
},
15+
}));
16+
17+
// TBD hackish mock:
18+
global.console = {
19+
info: (...args) => {
20+
mockpushit({ info: [].concat(args) });
21+
},
22+
log: (...args) => {
23+
mockpushit({ log: [].concat(args) });
24+
},
25+
warn: (...args) => {
26+
mockpushit({ warn: [].concat(args) });
27+
},
28+
};
29+
30+
test(`create alice-bobbi module with logging, with platforms: 'bogus'`, async () => {
31+
const args = ['alice-bobbi'];
32+
33+
const options = { platforms: 'bogus' };
34+
35+
func(args, null, options);
36+
37+
expect(mysnap).toMatchSnapshot();
38+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`create alice-bobbi module with logging, with platforms: '' 1`] = `
4+
Array [
5+
Object {
6+
"warn": Array [
7+
"While \`{DEFAULT_PACKAGE_IDENTIFIER}\` is the default package
8+
identifier, it is recommended to customize the package identifier.",
9+
],
10+
},
11+
Object {
12+
"info": Array [
13+
"CREATE new React Native module with the following options:
14+
15+
root moduleName: react-native-alice-bobbi
16+
name: alice-bobbi
17+
prefix:
18+
modulePrefix: react-native
19+
packageIdentifier: com.reactlibrary
20+
platforms:
21+
githubAccount: github_account
22+
authorName: Your Name
23+
authorEmail: yourname@email.com
24+
authorEmail: yourname@email.com
25+
license: MIT
26+
view: false
27+
useCocoapods: false
28+
generateExample: false
29+
exampleName: example
30+
",
31+
],
32+
},
33+
Object {
34+
"info": Array [
35+
"CREATE: Generating the React Native library module",
36+
],
37+
},
38+
Object {
39+
"ensureDir": "react-native-alice-bobbi",
40+
},
41+
]
42+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const func = require('../../../../../../../../lib/cli-command.js').func;
2+
3+
// special compact mocks for this test:
4+
const mysnap = [];
5+
const mockpushit = x => mysnap.push(x);
6+
jest.mock('fs-extra', () => ({
7+
outputFile: (outputFileName, theContent) => {
8+
mockpushit({ outputFileName, theContent });
9+
return Promise.resolve();
10+
},
11+
ensureDir: (dir) => {
12+
mockpushit({ ensureDir: dir });
13+
return Promise.resolve();
14+
},
15+
}));
16+
17+
// TBD hackish mock:
18+
global.console = {
19+
info: (...args) => {
20+
mockpushit({ info: [].concat(args) });
21+
},
22+
log: (...args) => {
23+
mockpushit({ log: [].concat(args) });
24+
},
25+
warn: (...args) => {
26+
mockpushit({ warn: [].concat(args) });
27+
},
28+
};
29+
30+
test(`create alice-bobbi module with logging, with platforms: ''`, async () => {
31+
const args = ['alice-bobbi'];
32+
33+
const options = { platforms: '' };
34+
35+
func(args, null, options);
36+
37+
expect(mysnap).toMatchSnapshot();
38+
});

0 commit comments

Comments
 (0)