Skip to content

Commit

Permalink
Fix mock.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Feb 10, 2024
1 parent e1e3768 commit 7d6730d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 162 deletions.
8 changes: 6 additions & 2 deletions packages/cli/__mocks__/term-size.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = function size() {
function size() {
return { columns: 80, rows: 80 };
};
}

size.size = size;

module.exports = size;
174 changes: 24 additions & 150 deletions packages/cli/tests/__snapshots__/Failure.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,28 @@

exports[`<Failure /> > doesnt render code frame if a common error 1`] = `
"
 ERROR  Cannot read properties of undefined (reading 'columns')
src/components/Failure.tsx:57:29
54: return null;
55: }
56:
57: const width = screen.size().columns;
58: let type: StyleType = 'failure';
59: let cmd = \`\${delimiter}\${binName} \${commandLine}\`;
60: let arg = '';
- Failure.renderCodeFrame (src/components/Failure.tsx:57:29)
- Failure.render (src/components/Failure.tsx:164:12)
-finishClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8912:31)
-updateClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8862:24)
-beginWor (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.developm
ent.js:10500:16)
-Object.invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-rec
ackProd onciler.development.js:12101:10)
-invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler
ack .development.js:12292:31)
-beginWork$ (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.develo
pment.js:16531:7)
-performUnitOfW (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.de
rk velopment.js:15340:12)
-workLoopSyn (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.devel
opment.js:15268:5)
 ERROR 
Something is broken!
"
`;

exports[`<Failure /> > doesnt render code frame if arg not found 1`] = `
"
 ERROR  Cannot read properties of undefined (reading 'columns')
src/components/Failure.tsx:57:29
54: return null;
55: }
56:
57: const width = screen.size().columns;
58: let type: StyleType = 'failure';
59: let cmd = \`\${delimiter}\${binName} \${commandLine}\`;
60: let arg = '';
- Failure.renderCodeFrame (src/components/Failure.tsx:57:29)
- Failure.render (src/components/Failure.tsx:164:12)
-finishClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8912:31)
-updateClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8862:24)
-beginWor (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.developm
ent.js:10500:16)
-Object.invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-rec
ackProd onciler.development.js:12101:10)
-invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler
ack .development.js:12292:31)
-beginWork$ (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.develo
pment.js:16531:7)
-performUnitOfW (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.de
rk velopment.js:15340:12)
-workLoopSyn (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.devel
opment.js:15268:5)
 ERROR 
Flags and short option groups may not use inline values.
"
`;

exports[`<Failure /> > reduces command line by half when index appears off screen 1`] = `
"
ERROR Cannot read properties of undefined (reading 'columns')
src/components/Failure.tsx:57:29
54: return null;
55: }
56:
57: const width = screen.size().columns;
58: let type: StyleType = 'failure';
59: let cmd = \`\${delimiter}\${binName} \${commandLine}\`;
60: let arg = '';
- Failure.renderCodeFrame (src/components/Failure.tsx:57:29)
- Failure.render (src/components/Failure.tsx:164:12)
-finishClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8912:31)
-updateClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8862:24)
-beginWor (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.developm
ent.js:10500:16)
-Object.invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-rec
ackProd onciler.development.js:12101:10)
-invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler
ack .development.js:12292:31)
-beginWork$ (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.develo
pment.js:16531:7)
-performUnitOfW (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.de
rk velopment.js:15340:12)
-workLoopSyn (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.devel
opment.js:15268:5)
ERROR
Flags and short option groups may not use inline values.
… wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" --flag=123 -gSA "mmmmmmmmmmmm …
└────────┘
"
`;

Expand All @@ -123,36 +45,12 @@ exports[`<Failure /> > renders a parse error 1`] = `

exports[`<Failure /> > renders a parse error with a command line 1`] = `
"
ERROR Cannot read properties of undefined (reading 'columns')
src/components/Failure.tsx:57:29
54: return null;
55: }
56:
57: const width = screen.size().columns;
58: let type: StyleType = 'failure';
59: let cmd = \`\${delimiter}\${binName} \${commandLine}\`;
60: let arg = '';
- Failure.renderCodeFrame (src/components/Failure.tsx:57:29)
- Failure.render (src/components/Failure.tsx:164:12)
-finishClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8912:31)
-updateClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8862:24)
-beginWor (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.developm
ent.js:10500:16)
-Object.invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-rec
ackProd onciler.development.js:12101:10)
-invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler
ack .development.js:12292:31)
-beginWork$ (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.develo
pment.js:16531:7)
-performUnitOfW (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.de
rk velopment.js:15340:12)
-workLoopSyn (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.devel
opment.js:15268:5)
ERROR
Flags and short option groups may not use inline values.
$ boost --foo value --flag=123 -gSA
└────────┘
"
`;

Expand All @@ -166,35 +64,11 @@ exports[`<Failure /> > renders a validation error 1`] = `

exports[`<Failure /> > renders a validation error with a command line 1`] = `
"
ERROR Cannot read properties of undefined (reading 'columns')
src/components/Failure.tsx:57:29
54: return null;
55: }
56:
57: const width = screen.size().columns;
58: let type: StyleType = 'failure';
59: let cmd = \`\${delimiter}\${binName} \${commandLine}\`;
60: let arg = '';
- Failure.renderCodeFrame (src/components/Failure.tsx:57:29)
- Failure.render (src/components/Failure.tsx:164:12)
-finishClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8912:31)
-updateClassCompo (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.
ent development.js:8862:24)
-beginWor (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.developm
ent.js:10500:16)
-Object.invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-rec
ackProd onciler.development.js:12101:10)
-invokeGuardedCall (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler
ack .development.js:12292:31)
-beginWork$ (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.develo
pment.js:16531:7)
-performUnitOfW (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.de
rk velopment.js:15340:12)
-workLoopSyn (/Users/miles/Projects/boost/node_modules/react-reconciler/cjs/react-reconciler.devel
opment.js:15268:5)
ERROR
Not enough arity arguments.
$ boost --foo value --flag=123 -gSA
└───┘
"
`;
27 changes: 17 additions & 10 deletions packages/cli/tests/__snapshots__/Program.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports[`<Program /> > exit > renders a non-zero exit 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Fail!
"
`;

Expand All @@ -80,55 +80,59 @@ exports[`<Program /> > failure > renders if an error is thrown 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Broken!
"
`;

exports[`<Program /> > failure > renders when args parsing fails 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Unknown option "--foo" found. Did you mean "help"? [ARG:OPTION_UNKNOWN_MORE]
$ boost --foo
 └───┘
"
`;

exports[`<Program /> > failure > renders when invalid command name passed 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Unknown command "prune". Did you mean "build"? [CLI:COMMAND_UNKNOWN]
"
`;

exports[`<Program /> > failure > renders when misspelt command name passed 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Unknown command "buld". Did you mean "build"? [CLI:COMMAND_UNKNOWN]
"
`;

exports[`<Program /> > failure > renders when no commands could be found 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Failed to determine a command to run. [CLI:COMMAND_INVALID_RUN]
"
`;

exports[`<Program /> > failure > renders when no commands have been registered 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
No commands have been registered. At least 1 is required.
[CLI:COMMAND_NONE_REGISTERED]
"
`;

exports[`<Program /> > failure > renders with custom exit error 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Oops
"
`;

Expand Down Expand Up @@ -383,7 +387,10 @@ exports[`<Program /> > locale > errors for invalid \`--locale\` 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Locale must be in the format of "en" or "en-US".
$ boost --locale wtf
 └──────┘
"
`;

Expand Down Expand Up @@ -414,7 +421,7 @@ exports[`<Program /> > nested programs > bubbles up errors 1`] = `
"
 ERROR 
Cannot read properties of undefined (reading 'columns')
Bubbles
"
`;

Expand Down

0 comments on commit 7d6730d

Please sign in to comment.