-
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.
Merge pull request #6 from codeceptjs/move-to-ts
- Loading branch information
Showing
8 changed files
with
202 additions
and
50 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 |
---|---|---|
@@ -1,33 +1,35 @@ | ||
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Publish | ||
name: Publish npm Package | ||
|
||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
publish: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.release.target_commitish }} | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
cache: 'npm' | ||
- run: git config --global user.name "GitHub CD bot" | ||
- run: git config --global user.email "github-cd-bot@example.com" | ||
- run: npm version ${{ github.event.release.tag_name }} | ||
- uses: JS-DevTools/npm-publish@v1 | ||
with: | ||
token: ${{ secrets.NPM_TOKEN }} | ||
|
||
# push the version changes to GitHub | ||
- run: git push | ||
env: | ||
# The secret is passed automatically. Nothing to configure. | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: git config --global user.name "GitHub CD bot" | ||
- run: git config --global user.email "github-cd-bot@example.com" | ||
- name: Install deps | ||
run: npm i | ||
- name: Compile code | ||
run: npm run build | ||
- name: publish package | ||
run: npx semantic-release | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# push the version changes to GitHub | ||
- run: git add package.json && git commit -m'update version' && git push | ||
env: | ||
# The secret is passed automatically. Nothing to configure. | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
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,29 @@ | ||
name: Acceptance Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Run tests | ||
run: | | ||
npm i --force && npm run test |
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,4 @@ | ||
node_modules | ||
package-lock.json | ||
package-lock.json | ||
.idea | ||
dist |
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 @@ | ||
module.exports = { | ||
roots: ['<rootDir>'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleDirectories: ['node_modules', '.'] | ||
} |
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,78 @@ | ||
import Helper from '../src'; | ||
|
||
let _Helper; | ||
let _CustomHelper; | ||
|
||
class CustomHelper extends Helper { | ||
_validateConfig (config: any): any { | ||
super._validateConfig (config); | ||
if (!config.hello) throw Error('your config is not valid!'); | ||
} | ||
} | ||
|
||
describe('Abstract helper', () => { | ||
|
||
beforeAll(() => { | ||
_Helper = new Helper({ hello: 'world'}); | ||
}) | ||
|
||
test('create new helper successfully', () => { | ||
expect(_Helper.constructor.name).toEqual('Helper'); | ||
}); | ||
|
||
test('get the passed config', () => { | ||
expect(_Helper.config).toEqual({ hello: 'world'}); | ||
}); | ||
|
||
test('get the options from passed config', () => { | ||
_Helper._setConfig({ another: 'value' }); | ||
expect(_Helper.config).toEqual({ hello: 'world'}); | ||
expect(_Helper.options).toEqual({ another: 'value'}); | ||
}); | ||
|
||
test('throws error when nothing is passed to _useTo', () => { | ||
try { | ||
_Helper._useTo(); | ||
} catch (e) { | ||
expect(e.message).toContain('useTo requires "description:string" and "fn:async function" as arguments'); | ||
} | ||
}); | ||
|
||
test('throws error when fn is not passed to _useTo', () => { | ||
try { | ||
_Helper._useTo('hello'); | ||
} catch (e) { | ||
expect(e.message).toContain('useTo requires "description:string" and "fn:async function" as arguments'); | ||
} | ||
}); | ||
|
||
test('throws error when description is not passed to _useTo', () => { | ||
try { | ||
_Helper._useTo(undefined, function () {}); | ||
} catch (e) { | ||
expect(e.message).toContain('useTo requires "description:string" and "fn:async function" as arguments'); | ||
} | ||
}); | ||
|
||
test('throws error when non async fn is passed to _useTo', () => { | ||
try { | ||
_Helper._useTo('hello', function () {}); | ||
} catch (e) { | ||
expect(e.message).toContain('Not async function!'); | ||
} | ||
}); | ||
|
||
test('no error when all valid args passed to _useTo', async () => { | ||
const res = _Helper._useTo('hello', async function hello () { return 'hi' }); | ||
expect(await res).toEqual('hi'); | ||
}); | ||
|
||
test('validate config of custom helper', async () => { | ||
try { | ||
_CustomHelper = new CustomHelper({ }); | ||
_CustomHelper._validateConfig(_CustomHelper.config) | ||
} catch (e) { | ||
expect(e.message).toEqual('your config is not valid!'); | ||
} | ||
}); | ||
}) |
Oops, something went wrong.