Skip to content

Commit 55bf403

Browse files
author
Chris Brody
authored
CLI command function test fixes (#158)
for tests with bogus values of `platforms` * use internal 1ms timer to give CLI func output time to finish & update the affected snapshots * use a string replace WORKAROUND HACK to work around indeterminate elapsed time in the log * test updates for Windows These tests now cover *most* of the CLI function log output.
1 parent 805be22 commit 55bf403

File tree

4 files changed

+281
-4
lines changed

4 files changed

+281
-4
lines changed

tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/__snapshots__/cli-command-with-bogus-platforms-name.test.js.snap

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,133 @@ Array [
3737
Object {
3838
"ensureDir": "react-native-alice-bobbi",
3939
},
40+
Object {
41+
"ensureDir": "react-native-alice-bobbi/",
42+
},
43+
Object {
44+
"ensureDir": "react-native-alice-bobbi/",
45+
},
46+
Object {
47+
"ensureDir": "react-native-alice-bobbi/",
48+
},
49+
Object {
50+
"ensureDir": "react-native-alice-bobbi/",
51+
},
52+
Object {
53+
"ensureDir": "react-native-alice-bobbi/",
54+
},
55+
Object {
56+
"ensureDir": "react-native-alice-bobbi/",
57+
},
58+
Object {
59+
"outputFileName": "react-native-alice-bobbi/README.md",
60+
"theContent": "# react-native-alice-bobbi
61+
62+
## Getting started
63+
64+
\`$ npm install react-native-alice-bobbi --save\`
65+
66+
### Mostly automatic installation
67+
68+
\`$ react-native link react-native-alice-bobbi\`
69+
70+
### Manual installation
71+
72+
73+
74+
## Usage
75+
\`\`\`javascript
76+
import AliceBobbi from 'react-native-alice-bobbi';
77+
78+
// TODO: What to do with the module?
79+
AliceBobbi;
80+
\`\`\`
81+
",
82+
},
83+
Object {
84+
"outputFileName": "react-native-alice-bobbi/package.json",
85+
"theContent": "{
86+
\\"name\\": \\"react-native-alice-bobbi\\",
87+
\\"title\\": \\"React Native Alice Bobbi\\",
88+
\\"version\\": \\"1.0.0\\",
89+
\\"description\\": \\"TODO\\",
90+
\\"main\\": \\"index.js\\",
91+
\\"scripts\\": {
92+
\\"test\\": \\"echo \\\\\\"Error: no test specified\\\\\\" && exit 1\\"
93+
},
94+
\\"repository\\": {
95+
\\"type\\": \\"git\\",
96+
\\"url\\": \\"git+https://github.com/github_account/react-native-alice-bobbi.git\\",
97+
\\"baseUrl\\": \\"https://github.com/github_account/react-native-alice-bobbi\\"
98+
},
99+
\\"keywords\\": [
100+
\\"react-native\\"
101+
],
102+
\\"author\\": {
103+
\\"name\\": \\"Your Name\\",
104+
\\"email\\": \\"[email protected]\\"
105+
},
106+
\\"license\\": \\"MIT\\",
107+
\\"licenseFilename\\": \\"LICENSE\\",
108+
\\"readmeFilename\\": \\"README.md\\",
109+
\\"peerDependencies\\": {
110+
\\"react\\": \\"^16.8.1\\",
111+
\\"react-native\\": \\">=0.59.0-rc.0 <1.0.x\\"
112+
},
113+
\\"devDependencies\\": {
114+
\\"react\\": \\"^16.8.3\\",
115+
\\"react-native\\": \\"^0.59.10\\"
116+
}
117+
}
118+
",
119+
},
120+
Object {
121+
"outputFileName": "react-native-alice-bobbi/index.js",
122+
"theContent": "import { NativeModules } from 'react-native';
123+
124+
const { AliceBobbi } = NativeModules;
125+
126+
export default AliceBobbi;
127+
",
128+
},
129+
Object {
130+
"outputFileName": "react-native-alice-bobbi/.gitignore",
131+
"theContent": "# OSX
132+
#
133+
.DS_Store
134+
135+
# node.js
136+
#
137+
node_modules/
138+
npm-debug.log
139+
yarn-error.log
140+
",
141+
},
142+
Object {
143+
"outputFileName": "react-native-alice-bobbi/.gitattributes",
144+
"theContent": "",
145+
},
146+
Object {
147+
"outputFileName": "react-native-alice-bobbi/.npmignore",
148+
"theContent": "",
149+
},
150+
Object {
151+
"log": Array [
152+
"
153+
📚 Created library module react-native-alice-bobbi in \`./react-native-alice-bobbi\`.
154+
🕘 It took XXX.
155+
156+
====================================================
157+
YOU'RE ALL SET!
158+
159+
To build and run iOS example project, do:
160+
----
161+
cd react-native-alice-bobbi/undefined
162+
yarn
163+
react-native run-ios
164+
----
165+
",
166+
],
167+
},
40168
]
41169
`;

tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/bogus-name/cli-command-with-bogus-platforms-name.test.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ const mysnap = [];
55
const mockpushit = x => mysnap.push(x);
66
jest.mock('fs-extra', () => ({
77
outputFile: (outputFileName, theContent) => {
8-
mockpushit({ outputFileName, theContent });
8+
mockpushit({
9+
outputFileName: outputFileName.replace(/\\/g, '/'),
10+
theContent
11+
});
912
return Promise.resolve();
1013
},
1114
ensureDir: (dir) => {
12-
mockpushit({ ensureDir: dir });
15+
mockpushit({ ensureDir: dir.replace(/\\/g, '/') });
1316
return Promise.resolve();
1417
},
1518
}));
@@ -20,7 +23,10 @@ global.console = {
2023
mockpushit({ info: [].concat(args) });
2124
},
2225
log: (...args) => {
23-
mockpushit({ log: [].concat(args) });
26+
mockpushit({
27+
// TBD EXTRA WORKAROUND HACK for non-deterministic elapsed time in log
28+
log: args.map(line => line.replace(/It took.*s/g, 'It took XXX'))
29+
});
2430
},
2531
warn: (...args) => {
2632
mockpushit({ warn: [].concat(args) });
@@ -34,5 +40,11 @@ test(`create alice-bobbi module with logging, with platforms: 'bogus'`, async ()
3440

3541
func(args, null, options);
3642

43+
// Using a 1 ms timer to wait for the
44+
// CLI command function to finish.
45+
// FUTURE TBD this looks like a bad smell
46+
// that should be resolved someday.
47+
await new Promise((resolve) => setTimeout(resolve, 1));
48+
3749
expect(mysnap).toMatchSnapshot();
3850
});

tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/__snapshots__/cli-command-with-empty-platforms-string.test.js.snap

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,133 @@ Array [
3737
Object {
3838
"ensureDir": "react-native-alice-bobbi",
3939
},
40+
Object {
41+
"ensureDir": "react-native-alice-bobbi/",
42+
},
43+
Object {
44+
"ensureDir": "react-native-alice-bobbi/",
45+
},
46+
Object {
47+
"ensureDir": "react-native-alice-bobbi/",
48+
},
49+
Object {
50+
"ensureDir": "react-native-alice-bobbi/",
51+
},
52+
Object {
53+
"ensureDir": "react-native-alice-bobbi/",
54+
},
55+
Object {
56+
"ensureDir": "react-native-alice-bobbi/",
57+
},
58+
Object {
59+
"outputFileName": "react-native-alice-bobbi/README.md",
60+
"theContent": "# react-native-alice-bobbi
61+
62+
## Getting started
63+
64+
\`$ npm install react-native-alice-bobbi --save\`
65+
66+
### Mostly automatic installation
67+
68+
\`$ react-native link react-native-alice-bobbi\`
69+
70+
### Manual installation
71+
72+
73+
74+
## Usage
75+
\`\`\`javascript
76+
import AliceBobbi from 'react-native-alice-bobbi';
77+
78+
// TODO: What to do with the module?
79+
AliceBobbi;
80+
\`\`\`
81+
",
82+
},
83+
Object {
84+
"outputFileName": "react-native-alice-bobbi/package.json",
85+
"theContent": "{
86+
\\"name\\": \\"react-native-alice-bobbi\\",
87+
\\"title\\": \\"React Native Alice Bobbi\\",
88+
\\"version\\": \\"1.0.0\\",
89+
\\"description\\": \\"TODO\\",
90+
\\"main\\": \\"index.js\\",
91+
\\"scripts\\": {
92+
\\"test\\": \\"echo \\\\\\"Error: no test specified\\\\\\" && exit 1\\"
93+
},
94+
\\"repository\\": {
95+
\\"type\\": \\"git\\",
96+
\\"url\\": \\"git+https://github.com/github_account/react-native-alice-bobbi.git\\",
97+
\\"baseUrl\\": \\"https://github.com/github_account/react-native-alice-bobbi\\"
98+
},
99+
\\"keywords\\": [
100+
\\"react-native\\"
101+
],
102+
\\"author\\": {
103+
\\"name\\": \\"Your Name\\",
104+
\\"email\\": \\"[email protected]\\"
105+
},
106+
\\"license\\": \\"MIT\\",
107+
\\"licenseFilename\\": \\"LICENSE\\",
108+
\\"readmeFilename\\": \\"README.md\\",
109+
\\"peerDependencies\\": {
110+
\\"react\\": \\"^16.8.1\\",
111+
\\"react-native\\": \\">=0.59.0-rc.0 <1.0.x\\"
112+
},
113+
\\"devDependencies\\": {
114+
\\"react\\": \\"^16.8.3\\",
115+
\\"react-native\\": \\"^0.59.10\\"
116+
}
117+
}
118+
",
119+
},
120+
Object {
121+
"outputFileName": "react-native-alice-bobbi/index.js",
122+
"theContent": "import { NativeModules } from 'react-native';
123+
124+
const { AliceBobbi } = NativeModules;
125+
126+
export default AliceBobbi;
127+
",
128+
},
129+
Object {
130+
"outputFileName": "react-native-alice-bobbi/.gitignore",
131+
"theContent": "# OSX
132+
#
133+
.DS_Store
134+
135+
# node.js
136+
#
137+
node_modules/
138+
npm-debug.log
139+
yarn-error.log
140+
",
141+
},
142+
Object {
143+
"outputFileName": "react-native-alice-bobbi/.gitattributes",
144+
"theContent": "",
145+
},
146+
Object {
147+
"outputFileName": "react-native-alice-bobbi/.npmignore",
148+
"theContent": "",
149+
},
150+
Object {
151+
"log": Array [
152+
"
153+
📚 Created library module react-native-alice-bobbi in \`./react-native-alice-bobbi\`.
154+
🕘 It took XXX.
155+
156+
====================================================
157+
YOU'RE ALL SET!
158+
159+
To build and run iOS example project, do:
160+
----
161+
cd react-native-alice-bobbi/undefined
162+
yarn
163+
react-native run-ios
164+
----
165+
",
166+
],
167+
},
40168
]
41169
`;

tests/with-mocks/cli/command/func/with-logging/with-bogus-platforms/empty-string/cli-command-with-empty-platforms-string.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ global.console = {
2323
mockpushit({ info: [].concat(args) });
2424
},
2525
log: (...args) => {
26-
mockpushit({ log: [].concat(args) });
26+
mockpushit({
27+
// TBD EXTRA WORKAROUND HACK for non-deterministic elapsed time in log
28+
log: args.map(line => line.replace(/It took.*s/g, 'It took XXX'))
29+
});
2730
},
2831
warn: (...args) => {
2932
mockpushit({ warn: [].concat(args) });
@@ -37,5 +40,11 @@ test(`create alice-bobbi module with logging, with platforms: ''`, async () => {
3740

3841
func(args, null, options);
3942

43+
// Using a 1 ms timer to wait for the
44+
// CLI command function to finish.
45+
// FUTURE TBD this looks like a bad smell
46+
// that should be resolved someday.
47+
await new Promise((resolve) => setTimeout(resolve, 1));
48+
4049
expect(mysnap).toMatchSnapshot();
4150
});

0 commit comments

Comments
 (0)