Skip to content

Commit 609df02

Browse files
committed
test: Add E2E tests
1 parent 02fb9fb commit 609df02

File tree

13 files changed

+438
-458
lines changed

13 files changed

+438
-458
lines changed

.github/CONTRIBUTING.md

Lines changed: 18 additions & 0 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)
@@ -68,6 +69,23 @@ variables used by the GitHub Actions Toolkit. For more information, see the exam
6869
file, [`.env.example`](./.env.example), and the
6970
[GitHub Actions Documentation](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables).
7071

72+
## E2E tests
73+
74+
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.
75+
76+
```bash
77+
npm run test:e2e
78+
```
79+
80+
The tests require the following environment variables to be set, which can be defined in a `.env` file:
81+
82+
```txt .env
83+
CONFLUENCE_URL=https://your-confluence-url.net
84+
CONFLUENCE_PAT=******
85+
CONFLUENCE_README_PAGE_ID=page-id-of-the-readme-page
86+
CONFLUENCE_CHANGELOG_PAGE_ID=page-id-of-the-changelog-page
87+
```
88+
7189
## Branching model
7290

7391
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
runs:
8+
using: composite
9+
steps:
10+
- name: Setup Node.js
11+
id: setup-node
12+
uses: actions/setup-node@v4
13+
with:
14+
node-version-file: .node-version
15+
cache: npm
16+
- uses: DamianReeves/[email protected]
17+
with:
18+
path: .npmrc
19+
contents: |
20+
@tid-xcut:registry=https://nexus.tid.es/repository/npm-xcut-components/
21+
//nexus.tid.es/repository/npm-xcut-components/:_auth=${{ secrets.NPM_TOKEN_XCUT }}
22+
write-mode: append
23+
- name: Install Dependencies
24+
id: npm-ci
25+
run: npm ci

.github/workflows/build.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,8 @@ jobs:
2323
id: checkout
2424
uses: actions/checkout@v4
2525

26-
- name: Setup Node.js
26+
- uses: ./.github/actions/setup-node
2727
id: setup-node
28-
uses: actions/setup-node@v4
29-
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
4428

4529
- name: Lint
4630
id: npm-lint

.github/workflows/test-e2e.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ jobs:
4949
confluence-root-page-name: "Cross"
5050
confluence-space-key: ${{ vars.CONFLUENCE_SPACE_KEY }}
5151
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+
67+
- name: Run E2E Tests
68+
run: npm run test:e2e
69+
env:
70+
CONFLUENCE_URL: ${{ vars.CONFLUENCE_URL }}
71+
CONFLUENCE_PAT: ${{ secrets.CONFLUENCE_PAT }}
72+
CONFLUENCE_ROOT_PAGE_ID: ${{ vars.CONFLUENCE_ROOT_PAGE_ID }}
73+
CONFLUENCE_CHANGELOG_PAGE_ID: ${{ vars.CONFLUENCE_CHANGELOG_PAGE_ID }}

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)