Skip to content

Commit 3be0f93

Browse files
committed
add cypress git action
1 parent 8831ce7 commit 3be0f93

File tree

5 files changed

+126
-137
lines changed

5 files changed

+126
-137
lines changed

.github/workflows/cypress.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Cypress Tests using Cypress Docker Image
2+
3+
on: push
4+
5+
jobs:
6+
cypress-run:
7+
runs-on: ubuntu-22.04
8+
container:
9+
image: cypress/browsers:node-20.14.0-chrome-126.0.6478.114-1-ff-127.0.1-edge-126.0.2592.61-1
10+
options: --user 1001
11+
services:
12+
meilisearch:
13+
image: getmeili/meilisearch:latest
14+
env:
15+
MEILI_MASTER_KEY: 'masterKey'
16+
MEILI_NO_ANALYTICS: 'true'
17+
ports:
18+
- '7700:7700'
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
- name: Setup node
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: '20.x'
27+
cache: yarn
28+
- name: Cache dependencies
29+
uses: actions/cache@v3
30+
with:
31+
path: |
32+
./playground/node_modules
33+
key: ${{ hashFiles('playground/yarn.lock') }}
34+
- name: Install dependencies
35+
run: yarn --dev && yarn --cwd ./playground
36+
- name: Remove plugin symlink
37+
run: rm ./playground/src/plugins/meilisearch
38+
- name: Move plugin inside playground
39+
# Since the plugin is located at the root of the project but a symlink links
40+
# to it in ./playground/plugins/meilisearch it causes a circular
41+
# chaining problem.
42+
# Now that we removed the symlink (see previous step), we need to move our plugin in the
43+
# plugin directory of the playground.
44+
run: mkdir ./playground/src/plugins/meilisearch &&
45+
mv admin ./playground/src/plugins/meilisearch &&
46+
mv server ./playground/src/plugins/meilisearch &&
47+
mv strapi-admin.js ./playground/src/plugins/meilisearch &&
48+
mv strapi-server.js ./playground/src/plugins/meilisearch &&
49+
cp package.json ./playground/src/plugins/meilisearch
50+
51+
- name: Run e2e browser tests
52+
uses: cypress-io/github-action@v6
53+
with:
54+
build: yarn playground:build
55+
start: yarn playground:dev
56+
env: env=ci
57+
browser: chrome
58+
59+
- uses: actions/upload-artifact@v3
60+
if: failure()
61+
with:
62+
name: cypress-screenshots
63+
path: cypress/screenshots
64+
- uses: actions/upload-artifact@v3
65+
if: failure()
66+
with:
67+
name: cypress-videos
68+
path: cypress/videos

cypress/e2e/admin.cy.js

Lines changed: 40 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -98,94 +98,42 @@ describe('Strapi meilisearch plugin - administrator', () => {
9898
it('Add Collections to Meilisearch', () => {
9999
cy.openPluginPage(adminUrl)
100100

101-
if (['develop', 'watch', 'ci', 'prereleaseci'].includes(env)) {
102-
cy.clickAndCheckRowContent({
103-
rowNb: 1,
104-
contains: [
105-
{
106-
value: 'user',
107-
colIndex: 2,
108-
},
109-
{ value: 'Yes', colIndex: 3 },
110-
{
111-
value: 'Hooked',
112-
colIndex: 7,
113-
},
114-
],
115-
})
101+
cy.clickAndCheckRowContent({
102+
rowNb: 1,
103+
contains: ['user', 'Yes', 'Hooked'],
104+
})
116105

117-
cy.clickAndCheckRowContent({
118-
rowNb: 2,
119-
contains: [
120-
{
121-
value: 'about-us',
122-
colIndex: 2,
123-
},
124-
{ value: 'Yes', colIndex: 3 },
125-
{
126-
value: 'Hooked',
127-
colIndex: 7,
128-
},
129-
],
130-
})
106+
cy.clickAndCheckRowContent({
107+
rowNb: 2,
108+
contains: ['about-us', 'Yes', 'Hooked'],
109+
})
131110

132-
cy.clickAndCheckRowContent({
133-
rowNb: 3,
134-
contains: [
135-
{
136-
value: 'category',
137-
colIndex: 2,
138-
},
139-
{ value: 'Yes', colIndex: 3 },
140-
{
141-
value: 'Hooked',
142-
colIndex: 7,
143-
},
144-
],
145-
})
111+
cy.clickAndCheckRowContent({
112+
rowNb: 3,
113+
contains: ['category', 'Yes', 'Hooked'],
114+
})
146115

147-
cy.clickAndCheckRowContent({
148-
rowNb: 4,
149-
contains: [
150-
{
151-
value: 'homepage',
152-
colIndex: 2,
153-
},
154-
{ value: 'Yes', colIndex: 3 },
155-
{
156-
value: 'Hooked',
157-
colIndex: 7,
158-
},
159-
],
160-
})
116+
cy.clickAndCheckRowContent({
117+
rowNb: 4,
118+
contains: ['homepage', 'Yes', 'Hooked'],
119+
})
161120

162-
cy.clickAndCheckRowContent({
163-
rowNb: 5,
164-
contains: [
165-
{
166-
value: 'restaurant',
167-
colIndex: 2,
168-
},
169-
{ value: 'Yes', colIndex: 3 },
170-
{
171-
value: 'Hooked',
172-
colIndex: 7,
173-
},
174-
],
175-
})
176-
}
121+
cy.clickAndCheckRowContent({
122+
rowNb: 5,
123+
contains: ['restaurant', 'Yes', 'Hooked'],
124+
})
177125
})
178126

179127
it('Check for right number of documents indexed', () => {
180128
cy.openPluginPage(adminUrl)
181129

182-
cy.checkCollectionContent({ rowNb: 1, contains: [{ value: '1 / 2' }] })
183-
cy.checkCollectionContent({ rowNb: 2, contains: [{ value: '2 / 2' }] })
184-
cy.checkCollectionContent({ rowNb: 3, contains: [{ value: '3 / 3' }] })
185-
cy.checkCollectionContent({ rowNb: 4, contains: [{ value: '2 / 2' }] })
130+
cy.checkCollectionContent({ rowNb: 1, contains: ['1 / 2'] })
131+
cy.checkCollectionContent({ rowNb: 2, contains: ['2 / 2'] })
132+
cy.checkCollectionContent({ rowNb: 3, contains: ['3 / 3'] })
133+
cy.checkCollectionContent({ rowNb: 4, contains: ['2 / 2'] })
186134
cy.checkCollectionContent({
187135
rowNb: 5,
188-
contains: [{ value: '6200 / 6200' }],
136+
contains: ['6200 / 6200'],
189137
})
190138
})
191139

@@ -208,7 +156,7 @@ describe('Strapi meilisearch plugin - administrator', () => {
208156

209157
cy.checkCollectionContent({
210158
rowNb: 5,
211-
contains: [{ value: '6201 / 6201' }],
159+
contains: ['6201 / 6201'],
212160
})
213161
})
214162

@@ -233,7 +181,7 @@ describe('Strapi meilisearch plugin - administrator', () => {
233181

234182
cy.checkCollectionContent({
235183
rowNb: 5,
236-
contains: [{ value: '6200 / 6200' }],
184+
contains: ['6200 / 6200'],
237185
})
238186
})
239187

@@ -242,13 +190,7 @@ describe('Strapi meilisearch plugin - administrator', () => {
242190

243191
cy.clickAndCheckRowContent({
244192
rowNb: 1,
245-
contains: [
246-
{
247-
value: 'No',
248-
colIndex: 3,
249-
},
250-
{ value: 'Reload needed' },
251-
],
193+
contains: ['No', 'Reload needed'],
252194
})
253195

254196
cy.reloadServer()
@@ -257,13 +199,13 @@ describe('Strapi meilisearch plugin - administrator', () => {
257199
it('should show that first collection is not indexed', () => {
258200
cy.openPluginPage(adminUrl)
259201

260-
cy.checkCollectionContent({ rowNb: 1, contains: [{ value: '0 / 2' }] })
261-
cy.checkCollectionContent({ rowNb: 2, contains: [{ value: '2 / 2' }] })
262-
cy.checkCollectionContent({ rowNb: 3, contains: [{ value: '3 / 3' }] })
263-
cy.checkCollectionContent({ rowNb: 4, contains: [{ value: '2 / 2' }] })
202+
cy.checkCollectionContent({ rowNb: 1, contains: ['0 / 2'] })
203+
cy.checkCollectionContent({ rowNb: 2, contains: ['2 / 2'] })
204+
cy.checkCollectionContent({ rowNb: 3, contains: ['3 / 3'] })
205+
cy.checkCollectionContent({ rowNb: 4, contains: ['2 / 2'] })
264206
cy.checkCollectionContent({
265207
rowNb: 5,
266-
contains: [{ value: '6200 / 6200' }],
208+
contains: ['6200 / 6200'],
267209
})
268210
})
269211

@@ -272,17 +214,7 @@ describe('Strapi meilisearch plugin - administrator', () => {
272214

273215
cy.clickAndCheckRowContent({
274216
rowNb: 1,
275-
contains: [
276-
{
277-
value: 'user',
278-
colIndex: 2,
279-
},
280-
{ value: 'Yes', colIndex: 3 },
281-
{
282-
value: 'Hooked',
283-
colIndex: 7,
284-
},
285-
],
217+
contains: ['user', 'Yes', 'Hooked'],
286218
})
287219
})
288220

@@ -292,13 +224,7 @@ describe('Strapi meilisearch plugin - administrator', () => {
292224
for (let i = 1; i <= 5; i++) {
293225
cy.clickAndCheckRowContent({
294226
rowNb: i,
295-
contains: [
296-
{
297-
value: 'No',
298-
colIndex: 3,
299-
},
300-
{ value: 'Reload needed' },
301-
],
227+
contains: ['No', 'Reload needed'],
302228
})
303229
}
304230

@@ -308,13 +234,13 @@ describe('Strapi meilisearch plugin - administrator', () => {
308234
it('Check that collections are not in Meilisearch anymore', () => {
309235
cy.openPluginPage(adminUrl)
310236

311-
cy.checkCollectionContent({ rowNb: 1, contains: [{ value: '0 / 2' }] })
312-
cy.checkCollectionContent({ rowNb: 2, contains: [{ value: '0 / 2' }] })
313-
cy.checkCollectionContent({ rowNb: 3, contains: [{ value: '0 / 3' }] })
314-
cy.checkCollectionContent({ rowNb: 4, contains: [{ value: '0 / 2' }] })
237+
cy.checkCollectionContent({ rowNb: 1, contains: ['0 / 2'] })
238+
cy.checkCollectionContent({ rowNb: 2, contains: ['0 / 2'] })
239+
cy.checkCollectionContent({ rowNb: 3, contains: ['0 / 3'] })
240+
cy.checkCollectionContent({ rowNb: 4, contains: ['0 / 2'] })
315241
cy.checkCollectionContent({
316242
rowNb: 5,
317-
contains: [{ value: '0 / 6200' }],
243+
contains: ['0 / 6200'],
318244
})
319245
})
320246

@@ -336,9 +262,6 @@ describe('Strapi meilisearch plugin - administrator', () => {
336262
const row = `table[role='grid'] tbody tr:nth-child(1) input[type="checkbox"]`
337263

338264
cy.get(row).click()
339-
cy.contains(new RegExp(`Request to ${wrongHost}.* has failed`)).should(
340-
'be.visible',
341-
)
342265
cy.removeNotifications()
343266

344267
cy.get(row).should('not.be.checked')

cypress/support/commands.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ const clickCollection = ({ rowNb }) => {
8585
cy.get(`${row} input[type="checkbox"]`, { timeout: 10000 }).click({
8686
timeout: 10000,
8787
})
88-
removeNotifications()
8988
}
9089

9190
const checkCollectionContent = ({ rowNb, contains }) => {
9291
const row = `table[role='grid'] tbody tr:nth-child(${rowNb})`
93-
contains.map(({ value, colIndex }) =>
92+
contains.map(value =>
9493
cy
95-
.get(`${row}${colIndex ? ` td[aria-colindex=${colIndex}]` : ''}`, {
94+
.get(row, {
9695
timeout: 10000,
9796
})
9897
.contains(value, { timeout: 10000 }),

playground/config/plugins.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
const path = require('path');
1+
const path = require('path')
22

33
module.exports = ({ env }) => ({
4-
'meilisearch': {
4+
meilisearch: {
55
enabled: true,
66
resolve: path.resolve(__dirname, '../src/plugins/meilisearch'),
77
config: {
8-
restaurant: {
8+
'restaurant': {
99
filterEntry({ entry }) {
1010
return entry.id !== 2
1111
},
1212
transformEntry({ entry }) {
1313
return {
1414
...entry,
15-
categories: entry.categories.map(category => category.name)
16-
};
15+
categories: entry.categories.map(category => category.name),
16+
}
17+
},
18+
indexName: ['my_restaurant'],
19+
settings: {
20+
searchableAttributes: ['*'],
1721
},
18-
indexName: ["my_restaurant"],
19-
settings: {
20-
"searchableAttributes": ["*"]
21-
}
2222
},
23-
"about-us": {
24-
indexName: ["content"],
23+
'about-us': {
24+
indexName: ['content'],
2525
},
26-
homepage: {
27-
indexName: ["content"],
26+
'homepage': {
27+
indexName: ['content'],
2828
},
2929
// host: "http://localhost:7700",
3030
// apiKey: "masterKey"
31-
}
32-
}
33-
});
31+
},
32+
},
33+
})

playground/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"description": "A Strapi application",
66
"scripts": {
77
"dev": "strapi develop",
8-
"ci": "NODE_ENV=test strapi develop",
98
"start": "strapi start",
109
"build": "strapi build",
1110
"strapi": "strapi"

0 commit comments

Comments
 (0)