Skip to content

Commit 814a690

Browse files
committed
final test
1 parent 8f5f351 commit 814a690

File tree

10 files changed

+4259
-268
lines changed

10 files changed

+4259
-268
lines changed

.github/workflows/check-dist.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# In TypeScript actions, `dist/` is a special directory. When you reference
2+
# an action with the `uses:` property, `dist/index.js` is the code that will be
3+
# run. For this project, the `dist/index.js` file is transpiled from other
4+
# source files. This workflow ensures the `dist/` directory contains the
5+
# expected transpiled code.
6+
#
7+
# If this workflow is run from a feature branch, it will act as an additional CI
8+
# check and fail if the checked-in `dist/` directory does not match what is
9+
# expected from the build.
10+
name: Check Transpiled JavaScript
11+
12+
on:
13+
pull_request:
14+
branches:
15+
- main
16+
push:
17+
branches:
18+
- main
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
check-dist:
25+
name: Check dist/
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout
30+
id: checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Node.js
34+
id: setup-node
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version-file: .node-version
38+
cache: npm
39+
40+
- name: Install Dependencies
41+
id: install
42+
run: npm ci
43+
44+
- name: Build dist/ Directory
45+
id: build
46+
run: npm run bundle
47+
48+
# This will fail the workflow if the `dist/` directory is different than
49+
# expected.
50+
- name: Compare Directories
51+
id: diff
52+
run: |
53+
if [ ! -d dist/ ]; then
54+
echo "Expected dist/ directory does not exist. See status below:"
55+
ls -la ./
56+
exit 1
57+
fi
58+
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
59+
echo "Detected uncommitted changes after build. See status below:"
60+
git diff --ignore-space-at-eol --text dist/
61+
exit 1
62+
fi
63+
64+
# If `dist/` was different than expected, upload the expected version as a
65+
# workflow artifact.
66+
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
67+
name: Upload Artifact
68+
id: upload
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: dist
72+
path: dist/

.github/workflows/test.yml

+33-24
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,37 @@ on:
77
branches: ["main"]
88

99
jobs:
10-
test-non-main-repo-with-404:
11-
uses: ./.github/workflows/test-core.yml
12-
with:
13-
main-repo: false
14-
with-404: true
10+
test-typescript:
11+
name: TypeScript Tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Setup .NET
17+
uses: actions/setup-dotnet@v4
18+
with:
19+
dotnet-version: 9.0.x
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version-file: .node-version
24+
cache: npm
25+
- name: Install Dependencies
26+
run: npm ci
27+
- name: Run Jest Tests
28+
run: npm run ci-test
1529

16-
test-main-repo-with-404:
17-
uses: ./.github/workflows/test-core.yml
18-
with:
19-
mock-repo: na1307/na1307.github.io
20-
main-repo: true
21-
with-404: true
22-
23-
test-non-main-repo-without-404:
24-
uses: ./.github/workflows/test-core.yml
25-
with:
26-
main-repo: false
27-
with-404: false
28-
29-
test-main-repo-without-404:
30-
uses: ./.github/workflows/test-core.yml
31-
with:
32-
mock-repo: na1307/na1307.github.io
33-
main-repo: true
34-
with-404: false
30+
test-action:
31+
name: GitHub Actions Test
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
- name: Setup .NET
37+
uses: actions/setup-dotnet@v4
38+
with:
39+
dotnet-version: 9.0.x
40+
- name: GitHub Pages Blazor WASM
41+
uses: ./
42+
with:
43+
project-path: TestProject/TestProject.csproj

__tests__/e2e.test.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// tests/e2e.test.ts
2+
3+
import * as github from '@actions/github';
4+
import fs from 'fs';
5+
import path from 'path';
6+
import {main} from '../src/main';
7+
8+
jest.mock('@actions/github', () => {
9+
const originalModule = jest.requireActual('@actions/github');
10+
return {
11+
...originalModule,
12+
context: {
13+
...originalModule.context,
14+
repo: {owner: 'na1307', repo: 'blazor-github-pages'},
15+
},
16+
};
17+
});
18+
19+
describe('End-to-end test for dotnet-based Action', () => {
20+
const TEST_PROJ_NAME = 'TestProject';
21+
const PUBLISH_PATH = '_out';
22+
23+
beforeAll(() => {
24+
process.env['INPUT_PROJECT-PATH'] = path.join(TEST_PROJ_NAME, `${TEST_PROJ_NAME}.csproj`);
25+
process.env['INPUT_PUBLISH-PATH'] = PUBLISH_PATH;
26+
});
27+
28+
afterEach(() => {
29+
fs.rmSync(PUBLISH_PATH, {force: true, recursive: true});
30+
fs.rmSync(path.join(TEST_PROJ_NAME, 'bin'), {force: true, recursive: true});
31+
fs.rmSync(path.join(TEST_PROJ_NAME, 'obj'), {force: true, recursive: true});
32+
});
33+
34+
it('non-main repo', async () => {
35+
await main();
36+
37+
const publishedDir = path.join(PUBLISH_PATH, 'wwwroot');
38+
expect(fs.existsSync(publishedDir)).toBe(true);
39+
40+
const indexHtml = path.join(publishedDir, 'index.html');
41+
const indexContent = fs.readFileSync(indexHtml, 'utf8');
42+
expect(indexContent).toContain(`base href="/${github.context.repo.repo}/"`);
43+
44+
const fourOhFourHtml = path.join(publishedDir, '404.html');
45+
if (fs.existsSync(fourOhFourHtml)) {
46+
const fourOhFourContent = fs.readFileSync(fourOhFourHtml, 'utf8');
47+
expect(fourOhFourContent).toContain(`/${github.context.repo.repo}/?p=/`);
48+
}
49+
}, 60_000);
50+
51+
it('main repo', async () => {
52+
github.context.repo.repo = 'na1307.github.io';
53+
54+
await main();
55+
56+
const publishedDir = path.join(PUBLISH_PATH, 'wwwroot');
57+
expect(fs.existsSync(publishedDir)).toBe(true);
58+
59+
const indexHtml = path.join(publishedDir, 'index.html');
60+
const indexContent = fs.readFileSync(indexHtml, 'utf8');
61+
expect(indexContent).toContain('base href="/"');
62+
63+
const fourOhFourHtml = path.join(publishedDir, '404.html');
64+
if (fs.existsSync(fourOhFourHtml)) {
65+
const fourOhFourContent = fs.readFileSync(fourOhFourHtml, 'utf8');
66+
expect(fourOhFourContent).toContain('/?p=/');
67+
}
68+
}, 60_000);
69+
});

__tests__/index.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Unit tests for the action's entrypoint, src/index.ts
3+
*/
4+
5+
import * as main from '../src/main'
6+
7+
// Mock the action's entrypoint
8+
const runMock = jest.spyOn(main, 'main').mockImplementation()
9+
10+
describe('index', () => {
11+
it('calls run when imported', () => {
12+
// eslint-disable-next-line @typescript-eslint/no-require-imports
13+
require('../src/index')
14+
15+
expect(runMock).toHaveBeenCalled()
16+
})
17+
})

dist/index.js

+15-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)