-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement testing using node:assert & node:test
- Loading branch information
Showing
8 changed files
with
141 additions
and
34 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ node_modules | |
dist | ||
_workbench.ts | ||
docs | ||
.env |
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
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,9 @@ | ||
import {SUPPORTS_INTL} from './constants.js'; | ||
|
||
export function formatList(list: string[], type: Intl.ListFormatType): string { | ||
if (SUPPORTS_INTL) { | ||
return new Intl.ListFormat('en-US', {type}).format(list); | ||
} | ||
|
||
return list.join(', '); | ||
} |
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,78 @@ | ||
import 'dotenv/config'; | ||
|
||
import assert from 'node:assert/strict'; | ||
import {test} from 'node:test'; | ||
|
||
import {id, Hop, RuntimeType, validateId} from '../src/index.js'; | ||
|
||
const hop = new Hop( | ||
id(process.env.HOP_TOKEN, ['ptk', 'bearer', 'pat']), | ||
'https://api-staging.hop.io', | ||
); | ||
|
||
test('It validates that the token is valid', () => { | ||
assert(validateId('ptk_testing', 'ptk'), "Couldn't validate Project Token"); | ||
}); | ||
|
||
test('it creates a deployment', async t => { | ||
const redis = await hop.ignite.deployments.create({ | ||
version: '2022-05-17', | ||
name: 'redis', | ||
image: { | ||
name: 'redis', | ||
auth: null, | ||
gh_repo: null, | ||
}, | ||
container_strategy: 'manual', | ||
type: RuntimeType.PERSISTENT, | ||
env: {}, | ||
resources: { | ||
vcpu: 0.5, | ||
ram: '128mb', | ||
vgpu: [], | ||
}, | ||
}); | ||
|
||
assert.ok( | ||
validateId(redis.id, 'deployment'), | ||
"Couldn't validate deployment ID", | ||
); | ||
|
||
assert.equal(redis.name, 'redis'); | ||
assert.equal(typeof redis.created_at, 'string'); | ||
assert.doesNotThrow(() => new Date(redis.created_at)); | ||
|
||
t.todo('See if we can check the functions that exist on a deployment'); | ||
|
||
assert.deepStrictEqual(redis, { | ||
config: { | ||
container_strategy: 'manual', | ||
env: {}, | ||
image: { | ||
auth: null, | ||
name: 'redis:latest', | ||
}, | ||
resources: { | ||
ram: '128mb', | ||
vcpu: 0.5, | ||
}, | ||
restart_policy: 'on-failure', | ||
type: 'persistent', | ||
version: '2022-05-17', | ||
}, | ||
name: 'redis', | ||
container_count: 0, | ||
|
||
// These values are dynamic and will change | ||
// so we can't really test them with .deepStrictEqual | ||
created_at: redis.created_at, | ||
id: redis.id, | ||
createContainer: redis.createContainer, | ||
createGateway: redis.createGateway, | ||
delete: redis.delete, | ||
getContainers: redis.getContainers, | ||
}); | ||
|
||
// Cleanup | ||
await redis.delete(); | ||
}); |
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