-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef65a75
commit 77762eb
Showing
6 changed files
with
230 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Used for testing | ||
STATICKIT_TEST_DEPLOY_KEY= |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
node_modules | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
"yargs": "^14.0.0" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^8.1.0", | ||
"execa": "^2.0.4", | ||
"jest": "^24.9.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,74 @@ | ||
const parser = require('../src/parser'); | ||
const execa = require('execa'); | ||
const fs = require('fs').promises; | ||
require('dotenv').config(); | ||
|
||
it('returns help output', async () => { | ||
const output = await new Promise(resolve => { | ||
parser.parse('--help', (err, argv, output) => { | ||
resolve(output); | ||
}); | ||
const { stdout } = await execa('bin/statickit', ['--help']); | ||
expect(stdout).toMatch(/Performs a deployment/); | ||
}); | ||
|
||
it('returns an error if no config is present', async () => { | ||
try { | ||
await execa('bin/statickit', ['deploy']); | ||
} catch (result) { | ||
expect(result.exitCode).toBe(1); | ||
expect(result.stderr).toMatch(/Configuration not provided/); | ||
} | ||
}); | ||
|
||
it('returns an error if config is unparsable', async () => { | ||
try { | ||
await execa('bin/statickit', ['deploy', '-c', "'{'"]); | ||
} catch (result) { | ||
expect(result.exitCode).toBe(1); | ||
expect(result.stderr).toMatch(/Configuration could not be parsed/); | ||
} | ||
}); | ||
|
||
it('returns an error if deploy key is not found', async () => { | ||
try { | ||
await execa('bin/statickit', ['deploy', '-c', "'{}'"]); | ||
} catch (result) { | ||
expect(result.exitCode).toBe(1); | ||
expect(result.stderr).toMatch(/Deploy key not found/); | ||
} | ||
}); | ||
|
||
it('returns an error if deploy key is invalid', async () => { | ||
try { | ||
await execa('bin/statickit', ['deploy', '-c', "'{}'", '-k', 'invalidkey']); | ||
} catch (result) { | ||
console.log(result); | ||
expect(result.exitCode).toBe(1); | ||
expect(result.stderr).toMatch(/Deploy key is not valid/); | ||
} | ||
}); | ||
|
||
it('succeeds given valid params', async () => { | ||
const { stdout } = await execa('bin/statickit', [ | ||
'deploy', | ||
'-c', | ||
"'{}'", | ||
'-k', | ||
process.env.STATICKIT_TEST_DEPLOY_KEY | ||
]); | ||
expect(stdout).toMatch(/Deployment succeeded/); | ||
}); | ||
|
||
it('accepts a deploy key from env', async () => { | ||
const { stdout } = await execa('bin/statickit', ['deploy', '-c', "'{}'"], { | ||
env: { STATICKIT_DEPLOY_KEY: process.env.STATICKIT_TEST_DEPLOY_KEY } | ||
}); | ||
expect(stdout).toMatch(/Deployment succeeded/); | ||
}); | ||
|
||
it('accepts a config from the statickit.json file', async () => { | ||
await fs.writeFile('statickit.json', '{}', 'utf8'); | ||
|
||
const { stdout } = await execa('bin/statickit', ['deploy'], { | ||
env: { STATICKIT_DEPLOY_KEY: process.env.STATICKIT_TEST_DEPLOY_KEY } | ||
}); | ||
expect(stdout).toMatch(/Deployment succeeded/); | ||
|
||
expect(output).toMatch(/Performs a deployment/); | ||
await fs.unlink('statickit.json'); | ||
}); |