Skip to content

Commit

Permalink
test: add test for <Application>s onInit
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Sep 3, 2024
1 parent b91fa7e commit 110ba3d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
35 changes: 33 additions & 2 deletions .github/workflows/handle-release-branch-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ jobs:
with:
fetch-depth: 0

- name: Setup Project
- name: Setup project
uses: ./.github/actions/setup

- name: Build Project
run: npm run build
shell: bash

- name: Semantic Release
- name: Semantic release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: release
Expand All @@ -71,3 +71,34 @@ jobs:
if: ${{ steps.release.outputs.new_tag_version != '' }}
run: npm publish ./dist/*.tgz --tag ${{ (github.head_ref || github.ref_name) == 'main' && 'latest' || github.head_ref || github.ref_name }}
shell: bash

dev-publish:
name: 'Publish: Dev'
needs:
- verify
if: contains(fromJson('["refs/heads/alpha", "refs/heads/beta", "refs/heads/main"]'), github.ref) == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup project
uses: ./.github/actions/setup

- name: Build project
run: npm run build
shell: bash

- name: Get current version
run: echo "PACKAGE_VERSION=$(npm pkg get version | tr -d '"')" >> $GITHUB_ENV

- name: Setup dev version
run: echo "BRANCH_VERSION=$PACKAGE_VERSION-$BRANCH_NAME.${GITHUB_SHA::7}" >> $GITHUB_ENV

- name: Bump version
run: npm version $BRANCH_VERSION --no-git-tag-version --force

- name: Publish a dev release
run: npm publish --tag dev
33 changes: 33 additions & 0 deletions test/e2e/components/Application.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
describe,
expect,
it,
vi,
} from 'vitest';
import { render } from '@testing-library/react'

import { Application } from '../../../src/components/Application'
import { wait } from '../../utils/wait';

describe('Application', () =>
{
describe('onInit', () => {
it('runs the callback', async () => {
const onInitSpy = vi.fn()

const TestComponent = function() {
return (
<Application onInit={onInitSpy} />
)
}

render((
<TestComponent />
))

await wait(1000)

expect(onInitSpy.mock.calls.length).to.equal(1)
});
})
});

0 comments on commit 110ba3d

Please sign in to comment.