Skip to content

Commit 73f0629

Browse files
chore: add basic e2e tests for memory/redis with github actions
1 parent fb5c79c commit 73f0629

File tree

28 files changed

+760
-761
lines changed

28 files changed

+760
-761
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
types
22
tests
3-
**/node_modules/**
3+
**/node_modules/**
4+
CHANGELOG.md

.github/workflows/docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: docs
22

33
on:
4-
# trigger deployment on every push to main branch
4+
# trigger deployment on push to main branch and if docs/ is updated
55
push:
66
branches: [main]
7+
paths:
8+
- "docs/**"
79
# trigger deployment manually
810
workflow_dispatch:
911

@@ -21,7 +23,7 @@ jobs:
2123
uses: actions/setup-node@v1
2224
with:
2325
# choose node.js version to use
24-
node-version: '14'
26+
node-version: "14"
2527

2628
# cache node_modules
2729
- name: Cache dependencies
@@ -54,4 +56,4 @@ jobs:
5456
build_dir: docs/.vuepress/dist
5557
env:
5658
# @see https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: tests
2+
3+
on:
4+
# allow to be triggered by another workflow
5+
workflow_call:
6+
# trigger test on every push to main branch if packages/ is updated
7+
push:
8+
branches: [main]
9+
paths:
10+
- "packages/**"
11+
# trigger test on every PR if packages/ is updated
12+
pull_request:
13+
branches: [main]
14+
paths:
15+
- "packages/**"
16+
17+
jobs:
18+
linters:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions/setup-node@v1
24+
with:
25+
node-version: 14.x
26+
27+
# cache node_modules
28+
- name: Cache dependencies
29+
uses: actions/cache@v2
30+
id: yarn-cache
31+
with:
32+
path: |
33+
**/node_modules
34+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-yarn-
37+
38+
# install dependencies if the cache did not hit
39+
- name: Install dependencies
40+
if: steps.yarn-cache.outputs.cache-hit != 'true'
41+
run: yarn --frozen-lockfile
42+
43+
- name: Run linters check
44+
run: yarn test:lint
45+
46+
e2e_memory:
47+
runs-on: ubuntu-latest
48+
needs: [linters]
49+
50+
steps:
51+
- uses: actions/checkout@v2
52+
- uses: actions/setup-node@v1
53+
with:
54+
node-version: 14.x
55+
56+
# cache node_modules
57+
- name: Cache dependencies
58+
uses: actions/cache@v2
59+
id: yarn-cache
60+
with:
61+
path: |
62+
**/node_modules
63+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
64+
restore-keys: |
65+
${{ runner.os }}-yarn-
66+
67+
# install dependencies if the cache did not hit
68+
- name: Install dependencies
69+
if: steps.yarn-cache.outputs.cache-hit != 'true'
70+
run: yarn --frozen-lockfile
71+
72+
- name: Run e2e tests with memory provider
73+
run: yarn test:e2e:memory
74+
75+
e2e_redis:
76+
runs-on: ubuntu-latest
77+
needs: [linters]
78+
79+
services:
80+
redis:
81+
image: bitnami/redis:latest
82+
env:
83+
ALLOW_EMPTY_PASSWORD: yes
84+
ports:
85+
# Opens tcp port 6379 on the host and service container
86+
- 6379:6379
87+
88+
steps:
89+
- uses: actions/checkout@v2
90+
- uses: actions/setup-node@v1
91+
with:
92+
node-version: 14.x
93+
94+
# cache node_modules
95+
- name: Cache dependencies
96+
uses: actions/cache@v2
97+
id: yarn-cache
98+
with:
99+
path: |
100+
**/node_modules
101+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
102+
restore-keys: |
103+
${{ runner.os }}-yarn-
104+
105+
# install dependencies if the cache did not hit
106+
- name: Install dependencies
107+
if: steps.yarn-cache.outputs.cache-hit != 'true'
108+
run: yarn --frozen-lockfile
109+
110+
- name: Run e2e tests with memory provider
111+
run: yarn test:e2e:memory

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
module.exports = async () => ({
4+
verbose: true,
5+
});

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"dev:redis": "yarn workspace @strapi-plugin-rest-cache/playground-redis develop",
1616
"dev:couchbase": "yarn workspace @strapi-plugin-rest-cache/playground-couchbase develop",
1717
"lint": "lerna run lint --stream",
18-
"test": "lerna run test --stream"
18+
"test:lint": "lerna run test:lint --stream",
19+
"test:e2e": "run-s test:e2e:*",
20+
"test:e2e:memory": "yarn workspace @strapi-plugin-rest-cache/playground-memory test:e2e",
21+
"test:e2e:redis": "yarn workspace @strapi-plugin-rest-cache/playground-redis test:e2e"
1922
},
2023
"license": "MIT",
2124
"dependencies": {},
@@ -25,23 +28,17 @@
2528
"devDependencies": {
2629
"@strapi-community/eslint-config": "^0.2.0",
2730
"@strapi-community/eslint-config-admin": "^0.2.0",
31+
"@strapi-community/eslint-config-tests": "^0.2.0",
2832
"@vuepress/plugin-register-components": "^2.0.0-beta.36",
2933
"@vuepress/plugin-search": "^2.0.0-beta.36",
30-
"chai": "^4.3.6",
31-
"codecov": "^3.8.3",
3234
"eslint": "^8.10.0",
3335
"jest": "^27.5.1",
34-
"jest-cli": "^27.5.1",
35-
"jest-styled-components": "^7.0.2",
3636
"lerna": "^4.0.0",
3737
"lint-staged": "^12.3.5",
3838
"mermaid": "^8.14.0",
39-
"mocha": "^9.2.1",
4039
"npm-run-all": "^4.1.5",
4140
"prettier": "^2.5.1",
42-
"sinon": "^13.0.1",
4341
"supertest": "^6.2.2",
44-
"supertest-koa-agent": "^0.3.2",
4542
"vuepress": "^2.0.0-beta.36",
4643
"yorkie": "^2.0.0"
4744
},
@@ -53,12 +50,11 @@
5350
"npm": ">=6.0.0"
5451
},
5552
"lint-staged": {
56-
"*.ts": [
53+
"{packages,playgrounds}/**/*.{ts,js}": [
5754
"eslint --fix",
5855
"prettier --write"
5956
],
60-
"*.js": [
61-
"eslint --fix",
57+
"docs/**/*.md": [
6258
"prettier --write"
6359
]
6460
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
const { join } = require("path");
4+
5+
module.exports = () => ({
6+
connection: {
7+
client: "sqlite",
8+
connection: {
9+
filename: join(__dirname, "../../../", ".tmp/tests.db"),
10+
},
11+
useNullAsDefault: true,
12+
},
13+
});

playgrounds/memory/config/middlewares.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = [
55
"strapi::security",
66
"strapi::cors",
77
"strapi::poweredBy",
8-
"strapi::logger",
8+
// "strapi::logger",
99
"strapi::query",
1010
"strapi::session",
1111
"strapi::body",

playgrounds/memory/config/plugins.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@ module.exports = {
88
max: 32767,
99
},
1010
strategy: {
11-
debug: true,
1211
enableEtag: true,
1312
enableXCacheHeaders: true,
14-
enableAdminCTBMiddleware: true,
15-
clearRelatedCache: true,
16-
resetOnStartup: true,
17-
maxAge: 420000,
18-
keys: {
19-
useQueryParams: true,
20-
useHeaders: ["accept-encoding"],
21-
},
2213
contentTypes: [
2314
"api::article.article",
2415
"api::global.global",
@@ -36,7 +27,7 @@ module.exports = {
3627
path: "/api/categories/slug/:slug+",
3728
keys: {
3829
useQueryParams: ["populate", "locale"],
39-
useHeaders: ["accept-encoding"],
30+
useHeaders: [],
4031
},
4132
maxAge: 18000,
4233
method: "GET",

playgrounds/memory/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"develop": "strapi develop",
88
"start": "strapi start",
99
"build": "strapi build",
10-
"strapi": "strapi"
10+
"strapi": "strapi",
11+
"test": "run-s test:*",
12+
"test:e2e": "jest --detectOpenHandles --forceExit"
1113
},
1214
"dependencies": {
1315
"@strapi/plugin-i18n": "4.1.0",
@@ -19,6 +21,11 @@
1921
"strapi-plugin-rest-cache": "^4.2.0",
2022
"strapi-provider-rest-cache-memory": "^4.2.0"
2123
},
24+
"devDependencies": {
25+
"npm-run-all": "^4.1.5",
26+
"jest": "^27.5.1",
27+
"supertest": "^6.2.2"
28+
},
2229
"author": {
2330
"name": "A Strapi developer"
2431
},

playgrounds/memory/src/bootstrap.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async function importSeedData() {
175175
global: ["find"],
176176
homepage: ["find"],
177177
article: ["find", "findOne"],
178-
category: ["find", "findOne"],
178+
category: ["find", "findBySlug", "findOne"],
179179
writer: ["find", "findOne"],
180180
});
181181

@@ -192,9 +192,7 @@ module.exports = async () => {
192192

193193
if (shouldImportSeedData) {
194194
try {
195-
console.log("Setting up the template...");
196195
await importSeedData();
197-
console.log("Ready to go");
198196
} catch (error) {
199197
console.log("Could not import seed data");
200198
console.error(error);

0 commit comments

Comments
 (0)