Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit b5a93dc

Browse files
Merge pull request #49 from storyblok/fix/tests
fix: fixing broken tests
2 parents b5d196e + fbe5d0c commit b5a93dc

4 files changed

Lines changed: 35 additions & 12 deletions

File tree

.github/workflows/unit-tests.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Unit Tests Production'
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
8+
jobs:
9+
unit-tests:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
cache: 'yarn'
17+
- name: Install dependencies
18+
run: yarn install --frozen-lockfile
19+
- name: Clear jest cache
20+
run: yarn test:unit --clearCache
21+
- name: Run unit tests
22+
run: yarn test:unit --silent --ci

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"lint": "eslint src/",
2121
"lint:fix": "eslint src/ --fix",
22-
"test": "jest --silent",
22+
"test:unit": "jest --silent",
2323
"test:coverage": "jest --coverage"
2424
},
2525
"author": "Dominik Angerer <dominikangerer1@gmail.com>, Alexander Feiglstorfer <delooks@gmail.com>",

tests/units/delete-components.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ describe('testing deleteComponents', () => {
1919
const id = path.split('/')[1]
2020
return Promise.resolve({ data: { component: components[id] } })
2121
}),
22+
getComponents: jest.fn(() => {
23+
return components
24+
}),
2225
delete: jest.fn(() => Promise.resolve())
2326
}
2427
return deleteComponents(api, { source, reversed: false }).then(() => {
@@ -29,18 +32,16 @@ describe('testing deleteComponents', () => {
2932
it('api.deleteComponents reverse', () => {
3033
const source = 'components.js'
3134
const components = FAKE_COMPONENTS()
32-
const spy = jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify({
33-
components
34-
}))
35+
const copy = [...components]
36+
copy.splice(2, 1)
37+
const spy = jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify([...copy]))
3538
const api = {
3639
get: jest.fn((path) => {
3740
const id = path.split('/')[1]
3841
return Promise.resolve({ data: { component: components[id] } })
3942
}),
4043
getComponents: jest.fn(() => {
41-
const copy = [...components]
42-
copy.splice(3, 1)
43-
return copy
44+
return components
4445
}),
4546
delete: jest.fn(() => Promise.resolve())
4647
}

tests/units/pull-components.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('testing pullComponents', () => {
4040
}
4141

4242
const options = {
43-
compFileName: SPACE
43+
fileName: SPACE
4444
}
4545

4646
const expectFileName = `components.${SPACE}.json`
@@ -71,7 +71,7 @@ describe('testing pullComponents', () => {
7171
}
7272

7373
const options = {
74-
space: SPACE
74+
fileName: SPACE
7575
}
7676

7777
const expectComponentFileName = `components.${SPACE}.json`
@@ -108,7 +108,7 @@ describe('testing pullComponents', () => {
108108
}
109109

110110
const options = {
111-
space: SPACE,
111+
fileName: SPACE,
112112
separateFiles: true
113113
}
114114

@@ -117,15 +117,15 @@ describe('testing pullComponents', () => {
117117
expect(fs.writeFile.mock.calls.length).toBe(FAKE_COMPONENTS().length)
118118

119119
for (const comp in FAKE_COMPONENTS()) {
120-
const compFileName = `${FAKE_COMPONENTS()[comp].name}-${SPACE}.json`
120+
const fileName = `${FAKE_COMPONENTS()[comp].name}-${SPACE}.json`
121121
let data = FAKE_COMPONENTS()[comp]
122122
const [compPath, compData] = fs.writeFile.mock.calls[comp]
123123

124124
if (FAKE_COMPONENTS()[comp].name === 'logo') {
125125
data = { ...FAKE_COMPONENTS()[comp], component_group_name: '' }
126126
}
127127

128-
expect(compPath).toBe(`./${compFileName}`)
128+
expect(compPath).toBe(`./${fileName}`)
129129
expect(JSON.parse(compData)).toEqual(data)
130130
}
131131
})

0 commit comments

Comments
 (0)