Skip to content

Commit 7b85577

Browse files
authored
test: Add unit and E2E tests (#8)
* test: Add unit and E2E tests
1 parent 18fcb69 commit 7b85577

File tree

22 files changed

+828
-475
lines changed

22 files changed

+828
-475
lines changed

.github/CONTRIBUTING.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Thank you for being part of the Telefónica Innovación Digital Open Source Comm
66

77
- [Getting started](#getting-started)
88
- [Test the action locally](#test-the-action-locally)
9+
- [E2E tests](#e2e-tests)
910
- [Branching model](#branching-model)
1011
- [Pull Request](#pull-request)
1112
- [Release process](#release-process)
@@ -30,15 +31,13 @@ Thank you for being part of the Telefónica Innovación Digital Open Source Comm
3031
npm run package
3132
```
3233

33-
1. :white_check_mark: Run the tests
34+
1. :white_check_mark: Run the unit tests
3435

3536
```bash
36-
$ npm test
37-
38-
PASS ./index.test.js
39-
✓ throws invalid number (3ms)
40-
test runs (95ms)
37+
$ npm run test:unit
4138

39+
PASS test/unit/specs/main.spec.ts
40+
PASS test/unit/specs/index.spec.ts
4241
...
4342

4443
## Test the action locally
@@ -68,6 +67,22 @@ variables used by the GitHub Actions Toolkit. For more information, see the exam
6867
file, [`.env.example`](./.env.example), and the
6968
[GitHub Actions Documentation](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).
7069

70+
## E2E tests
71+
72+
This project includes end-to-end tests, consisting in a workflow that uses the action to sync the documentation of the project itself to a Confluence page, and then checks if the page was updated correctly.
73+
74+
```bash
75+
npm run test:e2e
76+
```
77+
78+
The tests require the following environment variables to be set, which can be defined in a `.env` file:
79+
80+
```txt .env
81+
CONFLUENCE_URL=https://your-confluence-url.net
82+
CONFLUENCE_PAT=******
83+
CONFLUENCE_README_PAGE_ID=page-id-of-the-readme-page
84+
```
85+
7186
## Branching model
7287

7388
In short, we have a "main" branch and a "release" branch. The "main" branch must always reflect the latest stable published version of the packages in the repository. The "release" branch is used to prepare the release of features without having to promote any unpublished changes to the "main" branch. It is the default branch for PRs.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital and contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
name: Setup Node.js
5+
description: Setup the node.js environment
6+
7+
inputs:
8+
npm-token:
9+
description: 'The NPM token to use for authentication'
10+
required: true
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Setup Node.js
16+
id: setup-node
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version-file: .node-version
20+
cache: npm
21+
- uses: DamianReeves/[email protected]
22+
with:
23+
path: .npmrc
24+
contents: |
25+
@tid-xcut:registry=https://nexus.tid.es/repository/npm-xcut-components/
26+
//nexus.tid.es/repository/npm-xcut-components/:_auth=${{ inputs.npm-token }}
27+
write-mode: append
28+
- name: Install Dependencies
29+
shell: bash
30+
id: npm-ci
31+
run: npm ci

.github/workflows/build.yml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
branches:
1010
- main
1111
- release
12+
- test/add-tests
1213

1314
permissions:
1415
contents: read
@@ -23,24 +24,10 @@ jobs:
2324
id: checkout
2425
uses: actions/checkout@v4
2526

26-
- name: Setup Node.js
27+
- uses: ./.github/actions/setup-node
2728
id: setup-node
28-
uses: actions/setup-node@v4
2929
with:
30-
node-version-file: .node-version
31-
cache: npm
32-
33-
- uses: DamianReeves/[email protected]
34-
with:
35-
path: .npmrc
36-
contents: |
37-
@tid-xcut:registry=https://nexus.tid.es/repository/npm-xcut-components/
38-
//nexus.tid.es/repository/npm-xcut-components/:_auth=${{ secrets.NPM_TOKEN_XCUT }}
39-
write-mode: append
40-
41-
- name: Install Dependencies
42-
id: npm-ci
43-
run: npm ci
30+
npm-token: ${{ secrets.NPM_TOKEN_XCUT }}
4431

4532
- name: Lint
4633
id: npm-lint
@@ -54,10 +41,16 @@ jobs:
5441
id: npm-check-types
5542
run: npm run check:types
5643

57-
# TODO: Add unit tests
58-
#- name: Test
59-
# id: npm-test
60-
# run: npm run test
44+
- name: Test unit
45+
id: npm-test
46+
run: npm run test:unit
47+
48+
- name: Upload coverage
49+
id: upload-coverage
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: coverage
53+
path: coverage/
6154

6255
- name: Build dist/ Directory
6356
id: build

.github/workflows/test-e2e.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital and contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
name: Test E2E
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- release
11+
- test/add-tests
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
sync-to-confluence:
18+
environment: production
19+
name: Sync Docs to Confluence
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
id: checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Sync Readme
28+
id: sync-readme
29+
uses: ./
30+
with:
31+
mode: flat
32+
docs-dir: '.'
33+
files-pattern: 'README.md'
34+
confluence-url: ${{ vars.CONFLUENCE_URL }}
35+
confluence-root-page-id: ${{ vars.CONFLUENCE_ROOT_PAGE_ID }}
36+
confluence-root-page-name: "Cross"
37+
confluence-space-key: ${{ vars.CONFLUENCE_SPACE_KEY }}
38+
confluence-personal-access-token: ${{ secrets.CONFLUENCE_PAT }}
39+
40+
- name: Sync Changelog
41+
id: sync-changelog
42+
uses: ./
43+
with:
44+
mode: flat
45+
docs-dir: '.'
46+
files-pattern: 'CHANGELOG.md'
47+
confluence-url: ${{ vars.CONFLUENCE_URL }}
48+
confluence-root-page-id: ${{ vars.CONFLUENCE_ROOT_PAGE_ID }}
49+
confluence-root-page-name: "Cross"
50+
confluence-space-key: ${{ vars.CONFLUENCE_SPACE_KEY }}
51+
confluence-personal-access-token: ${{ secrets.CONFLUENCE_PAT }}
52+
53+
test-e2e:
54+
environment: production
55+
name: Test E2E
56+
runs-on: ubuntu-latest
57+
needs: sync-to-confluence
58+
59+
steps:
60+
- name: Checkout
61+
id: checkout
62+
uses: actions/checkout@v4
63+
64+
- uses: ./.github/actions/setup-node
65+
id: setup-node
66+
with:
67+
npm-token: ${{ secrets.NPM_TOKEN_XCUT }}
68+
69+
- name: Run E2E Tests
70+
run: npm run test:e2e
71+
env:
72+
CONFLUENCE_URL: ${{ vars.CONFLUENCE_URL }}
73+
CONFLUENCE_PAT: ${{ secrets.CONFLUENCE_PAT }}
74+
CONFLUENCE_ROOT_PAGE_ID: ${{ vars.CONFLUENCE_ROOT_PAGE_ID }}
75+
CONFLUENCE_CHANGELOG_PAGE_ID: ${{ vars.CONFLUENCE_CHANGELOG_PAGE_ID }}

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
sync_to_confluence: true
3+
title: "[Markdown Confluence Sync] Releases"
4+
---
5+
16
# Changelog
27

38
All notable changes to this project will be documented in this file.
@@ -11,6 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1116
#### Deprecated
1217
#### Removed
1318

19+
## [1.0.0] - 2024-11-28
20+
21+
### Added
22+
23+
* test: Add E2E tests
24+
1425
## [1.0.0-beta.4] - 2024-11-28
1526

1627
### Added

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
sync_to_confluence: true
3+
title: "Markdown Confluence Sync"
4+
confluence_page_id: "333418648"
5+
---
6+
17
# Markdown Confluence Sync action
28

39
This action syncs markdown files to Confluence using the [Markdown Confluence Sync](https://github.com/Telefonica/cross-confluence-tools/tree/main/components/markdown-confluence-sync) library.

dist/index.js

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,24 @@ export default [
119119
},
120120
},
121121
{
122-
files: ["**/*.spec.js", "**/*.test.js", "**/*.spec.ts", "**/*.test.ts"],
122+
files: ["test/**/*.ts"],
123123
plugins: {
124124
jest: pluginJest,
125125
},
126126
...pluginJest.configs["flat/recommended"],
127127
languageOptions: {
128128
globals: pluginJest.environments.globals.globals,
129129
},
130+
settings: {
131+
"import/resolver": {
132+
typescript: {
133+
extensions: [".ts", ".tsx"],
134+
alwaysTryTypes: true,
135+
project: ["./test/tsconfig.json"],
136+
},
137+
node: true,
138+
},
139+
},
130140
rules: {
131141
...pluginJest.configs["flat/all"].rules,
132142
"jest/no-disabled-tests": "error",

jest.e2e.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
2+
export default {
3+
// Automatically clear mock calls and instances between every test
4+
clearMocks: true,
5+
6+
// Indicates whether the coverage information should be collected while executing the test
7+
collectCoverage: false,
8+
9+
testTimeout: 120000,
10+
11+
// The glob patterns Jest uses to detect test files
12+
testMatch: ["<rootDir>/test/e2e/specs/*.spec.ts"],
13+
14+
setupFiles: ["<rootDir>/test/e2e/support/setup.ts"],
15+
16+
transform: {
17+
"^.+.ts$": [
18+
"ts-jest",
19+
{
20+
tsconfig: "test/tsconfig.json",
21+
},
22+
],
23+
},
24+
};

0 commit comments

Comments
 (0)