-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): basic cli usage and exceptions
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
colllections: | ||
- name: noFields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { exec as _exec } from 'node:child_process'; | ||
import { promisify } from 'node:util'; | ||
|
||
const exec = promisify(_exec); | ||
const cmd = 'node --loader ts-node/esm src/cli.ts'; | ||
|
||
describe('cli', () => { | ||
it('throws an error if no config path is provided', async () => { | ||
const runsOrFails = () => exec(`${cmd} -t path/to/target`); | ||
await expect(runsOrFails).rejects.toThrow('Missing required argument: --config.'); | ||
}); | ||
|
||
it('throws an error if no target path is provided', async () => { | ||
const runsOrFails = () => exec(`${cmd} -c path/to/config.yml`); | ||
await expect(runsOrFails).rejects.toThrow('Missing required argument: --target.'); | ||
}); | ||
|
||
it('throws an error if the config path is invalid', async () => { | ||
const runsOrFails = () => exec(`${cmd} -c path/to/config.yml -t tmp`); | ||
await expect(runsOrFails).rejects.toThrow('Error: File not found: path/to/config.yml'); | ||
}); | ||
|
||
it('does not throw if the config can not be parsed', async () => { | ||
const runsOrFails = () => exec(`${cmd} -c public/examples/invalid.yml -t tmp`); | ||
await expect(runsOrFails()).resolves.toEqual({ stdout: '', stderr: '' }); | ||
}); | ||
|
||
it('loads and transforms a given config', async () => { | ||
const { stdout } = await exec(`${cmd} -c public/examples/blog.yml -t tmp`); | ||
expect(stdout).toEqual(expect.stringContaining('> blog schema written to')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters