-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add testing for set-tokens.ts (#126)
* test: remove main * test: add getPublishRepo() * test: Add setPersonalToken() * test: Add setGithubToken() * test: add showInputs() * test: .nojekyll already exists * test: ignore jest/expect-expect * refactor: squash inputs log * fix: throw error message
- Loading branch information
Showing
9 changed files
with
306 additions
and
106 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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { | ||
getPublishRepo, | ||
setPersonalToken, | ||
setGithubToken | ||
} from '../src/set-tokens'; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
}); | ||
|
||
// afterEach(() => { | ||
|
||
// }); | ||
|
||
describe('getPublishRepo()', () => { | ||
test('return repository name', () => { | ||
const test = getPublishRepo('', 'owner', 'repo'); | ||
expect(test).toMatch('owner/repo'); | ||
}); | ||
|
||
test('return external repository name', () => { | ||
const test = getPublishRepo('extOwner/extRepo', 'owner', 'repo'); | ||
expect(test).toMatch('extOwner/extRepo'); | ||
}); | ||
}); | ||
|
||
describe('setGithubToken()', () => { | ||
test('return remote url with GITHUB_TOKEN gh-pages', () => { | ||
const expected = | ||
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; | ||
const test = setGithubToken( | ||
'GITHUB_TOKEN', | ||
'owner/repo', | ||
'gh-pages', | ||
'', | ||
'refs/heads/master', | ||
'push' | ||
); | ||
expect(test).toMatch(expected); | ||
}); | ||
|
||
test('return remote url with GITHUB_TOKEN master', () => { | ||
const expected = | ||
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; | ||
const test = setGithubToken( | ||
'GITHUB_TOKEN', | ||
'owner/repo', | ||
'master', | ||
'', | ||
'refs/heads/source', | ||
'push' | ||
); | ||
expect(test).toMatch(expected); | ||
}); | ||
|
||
test('throw error master to master', () => { | ||
expect(() => { | ||
setGithubToken( | ||
'GITHUB_TOKEN', | ||
'owner/repo', | ||
'master', | ||
'', | ||
'refs/heads/master', | ||
'push' | ||
); | ||
}).toThrowError('You deploy from master to master'); | ||
}); | ||
|
||
test('throw error external repository with GITHUB_TOKEN', () => { | ||
expect(() => { | ||
setGithubToken( | ||
'GITHUB_TOKEN', | ||
'owner/repo', | ||
'gh-pages', | ||
'extOwner/extRepo', | ||
'refs/heads/master', | ||
'push' | ||
); | ||
}).toThrowError( | ||
'GITHUB_TOKEN does not support to push to an external repository' | ||
); | ||
}); | ||
|
||
test('return remote url with GITHUB_TOKEN pull_request', () => { | ||
const expected = | ||
'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; | ||
const test = setGithubToken( | ||
'GITHUB_TOKEN', | ||
'owner/repo', | ||
'gh-pages', | ||
'', | ||
'refs/pull/29/merge', | ||
'pull_request' | ||
); | ||
expect(test).toMatch(expected); | ||
}); | ||
}); | ||
|
||
describe('setPersonalToken()', () => { | ||
test('return remote url with personal access token', () => { | ||
const expected = 'https://x-access-token:pat@github.com/owner/repo.git'; | ||
const test = setPersonalToken('pat', 'owner/repo'); | ||
expect(test).toMatch(expected); | ||
}); | ||
}); |
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
Oops, something went wrong.