diff options
author | 2022-05-31 17:05:30 +0200 | |
---|---|---|
committer | 2022-05-31 19:20:16 +0200 | |
commit | 9edbe049aa4c4ba3b57fccc2d00dc10beadfcabd (patch) | |
tree | 6418ca8792d63bbffbecca36c77380be3a029820 | |
parent | chore(deps): bump dependencies (diff) | |
download | sophie-main.tar.gz sophie-main.tar.zst sophie-main.zip |
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
-rw-r--r-- | .gitlab-ci.yml | 19 | ||||
-rw-r--r-- | package.json | 5 | ||||
-rw-r--r-- | packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts | 34 | ||||
-rw-r--r-- | packages/test-utils/package.json | 4 | ||||
-rw-r--r-- | packages/test-utils/src/index.ts | 7 | ||||
-rw-r--r-- | packages/test-utils/src/testIf.ts | 70 | ||||
-rw-r--r-- | yarn.lock | 2 |
7 files changed, 121 insertions, 20 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f129977..d38a1bc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml | |||
@@ -7,6 +7,7 @@ cache: | |||
7 | stages: | 7 | stages: |
8 | - code-quality | 8 | - code-quality |
9 | - test | 9 | - test |
10 | - integ | ||
10 | - build | 11 | - build |
11 | 12 | ||
12 | default: | 13 | default: |
@@ -40,6 +41,23 @@ test: | |||
40 | path: coverage/test/cobertura-coverage.xml | 41 | path: coverage/test/cobertura-coverage.xml |
41 | junit: junit.xml | 42 | junit: junit.xml |
42 | 43 | ||
44 | integ: | ||
45 | stage: integ | ||
46 | coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/ | ||
47 | before_script: | ||
48 | - apt-get update | ||
49 | - apt-get install -y dbus-x11 libasound2 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libgtk-3-0 libnss3 xvfb | ||
50 | - yarn install --immutable | ||
51 | script: | ||
52 | - yarn test:integ:xvfb:ci | ||
53 | - yarn test:integ:check-exit | ||
54 | artifacts: | ||
55 | reports: | ||
56 | coverage_report: | ||
57 | coverage_format: cobertura | ||
58 | path: coverage/integ/cobertura-coverage.xml | ||
59 | junit: junit.xml | ||
60 | |||
43 | # TODO: GitlabCI free runners are only for linux - need to investigate for macos and windows artifacts | 61 | # TODO: GitlabCI free runners are only for linux - need to investigate for macos and windows artifacts |
44 | build: | 62 | build: |
45 | stage: build | 63 | stage: build |
@@ -47,6 +65,7 @@ build: | |||
47 | - yarn compile | 65 | - yarn compile |
48 | # TODO: Need to publish the built distributable file | 66 | # TODO: Need to publish the built distributable file |
49 | artifacts: | 67 | artifacts: |
68 | expire_in: 1 week | ||
50 | paths: | 69 | paths: |
51 | - dist/ | 70 | - dist/ |
52 | exclude: | 71 | exclude: |
diff --git a/package.json b/package.json index 625f3b6..bd72a39 100644 --- a/package.json +++ b/package.json | |||
@@ -21,11 +21,12 @@ | |||
21 | "scripts": { | 21 | "scripts": { |
22 | "clean": "rimraf coverage dist 'packages/*/dist' 'packages/*/*.tsbuildinfo' .vite", | 22 | "clean": "rimraf coverage dist 'packages/*/dist' 'packages/*/*.tsbuildinfo' .vite", |
23 | "test": "node --experimental-vm-modules --no-warnings $(yarn bin jest)", | 23 | "test": "node --experimental-vm-modules --no-warnings $(yarn bin jest)", |
24 | "test:ci": "yarn test --ci --coverage --reporters=default --reporters=jest-junit", | 24 | "test:ci": "cross-env DISABLE_GPU=true JEST_JUNIT_SUITE_NAME=\"{filepath}\" JEST_JUNIT_CLASSNAME=\"{filepath}\" JEST_JUNIT_ADD_FILE_ATTRIBUTE=true JEST_JUNIT_REPORT_TEST_SUITE_ERRORS=true yarn test --ci --coverage --reporters=default --reporters=jest-junit", |
25 | "test:integ": "electron scripts/electronJest.cjs --user-data-dir=userDataDir/integ --config=jest.integ.config.cjs --runInBand", | 25 | "test:integ": "electron scripts/electronJest.cjs --user-data-dir=userDataDir/integ --config=jest.integ.config.cjs --runInBand", |
26 | "test:integ:xvfb": "cross-env DISABLE_GPU=true xvfb-run -s \"-screen 0 1920x1080x24\" electron scripts/electronJest.cjs --user-data-dir=userDataDir/integ --disable-features=WebRTCPipeWireCapturer --ozone-platform=x11 --config=jest.integ.config.cjs --runInBand", | 26 | "test:integ:xvfb": "cross-env DISABLE_GPU=true xvfb-run -s \"-screen 0 1920x1080x24\" electron scripts/electronJest.cjs --user-data-dir=userDataDir/integ --disable-features=WebRTCPipeWireCapturer --ozone-platform=x11 --config=jest.integ.config.cjs --runInBand", |
27 | "test:integ:ci": "cross-env DISABLE_GPU=true yarn test:integ --ci --coverage --reporters=default --reporters=jest-junit", | 27 | "test:integ:ci": "cross-env DISABLE_GPU=true yarn test:integ --ci --coverage --reporters=default --reporters=jest-junit", |
28 | "test:integ:xvfb:ci": "yarn test:integ:xvfb --ci --coverage --reporters=default --reporters=jest-junit", | 28 | "test:integ:xvfb:ci": "cross-env DISABLE_GPU=true JEST_JUNIT_SUITE_NAME=\"{filepath}\" JEST_JUNIT_CLASSNAME=\"{filepath}\" JEST_JUNIT_ADD_FILE_ATTRIBUTE=true JEST_JUNIT_REPORT_TEST_SUITE_ERRORS=true xvfb-run -s \"-screen 0 1920x1080x24\" electron scripts/electronJest.cjs --no-sandbox --user-data-dir=userDataDir/integ --disable-features=WebRTCPipeWireCapturer --ozone-platform=x11 --config=jest.integ.config.cjs --runInBand --ci --coverage --reporters=default --reporters=jest-junit", |
29 | "test:integ:check-exit": "grep -qF 'failures=\"0\" errors=\"0\"' junit.xml", | ||
29 | "build": "node scripts/build.js", | 30 | "build": "node scripts/build.js", |
30 | "precompile": "cross-env MODE=production yarn run build", | 31 | "precompile": "cross-env MODE=production yarn run build", |
31 | "compile": "yarn precompile && yarn compile:electron-builder", | 32 | "compile": "yarn precompile && yarn compile:electron-builder", |
diff --git a/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts b/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts index dd4aaaa..c443d99 100644 --- a/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts +++ b/packages/main/src/infrastructure/config/impl/__tests__/ConfigFile.integ.test.ts | |||
@@ -29,10 +29,11 @@ import { | |||
29 | utimes, | 29 | utimes, |
30 | writeFile, | 30 | writeFile, |
31 | } from 'node:fs/promises'; | 31 | } from 'node:fs/promises'; |
32 | import { tmpdir } from 'node:os'; | 32 | import { platform, tmpdir, userInfo } from 'node:os'; |
33 | import path from 'node:path'; | 33 | import path from 'node:path'; |
34 | 34 | ||
35 | import { jest } from '@jest/globals'; | 35 | import { jest } from '@jest/globals'; |
36 | import { testIf } from '@sophie/test-utils'; | ||
36 | import { mocked } from 'jest-mock'; | 37 | import { mocked } from 'jest-mock'; |
37 | 38 | ||
38 | import Disposer from '../../../../utils/Disposer.js'; | 39 | import Disposer from '../../../../utils/Disposer.js'; |
@@ -249,19 +250,24 @@ describe('watchConfig', () => { | |||
249 | expect(callback).toHaveBeenCalled(); | 250 | expect(callback).toHaveBeenCalled(); |
250 | }); | 251 | }); |
251 | 252 | ||
252 | test('handles other filesystem errors', async () => { | 253 | // We can only cause a filesystem error by changing permissions if we run on a POSIX-like |
253 | const { mode } = await stat(userDataDir!); | 254 | // system and we aren't root (i.e., not in CI). |
254 | await writeFile(configFilePath, 'Hi Mars!', 'utf8'); | 255 | testIf(platform() !== 'win32' && userInfo().uid !== 0)( |
255 | // Remove permission to force a filesystem error. | 256 | 'handles other filesystem errors', |
256 | // eslint-disable-next-line no-bitwise -- Compute reduced permissions. | 257 | async () => { |
257 | await chmod(userDataDir!, mode & 0o666); | 258 | const { mode } = await stat(userDataDir!); |
258 | try { | 259 | await writeFile(configFilePath, 'Hi Mars!', 'utf8'); |
259 | await catchUpWithFilesystem(); | 260 | // Remove permission to force a filesystem error. |
260 | expect(callback).not.toHaveBeenCalled(); | 261 | // eslint-disable-next-line no-bitwise -- Compute reduced permissions. |
261 | } finally { | 262 | await chmod(userDataDir!, mode & 0o666); |
262 | await chmod(userDataDir!, mode); | 263 | try { |
263 | } | 264 | await catchUpWithFilesystem(); |
264 | }); | 265 | expect(callback).not.toHaveBeenCalled(); |
266 | } finally { | ||
267 | await chmod(userDataDir!, mode); | ||
268 | } | ||
269 | }, | ||
270 | ); | ||
265 | 271 | ||
266 | test('does not notify when the modification date is prior to the last write', async () => { | 272 | test('does not notify when the modification date is prior to the last write', async () => { |
267 | await repository.writeConfig('Hello World!'); | 273 | await repository.writeConfig('Hello World!'); |
diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 93f1626..8243cc5 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json | |||
@@ -10,6 +10,10 @@ | |||
10 | "types": "yarn g:types" | 10 | "types": "yarn g:types" |
11 | }, | 11 | }, |
12 | "dependencies": { | 12 | "dependencies": { |
13 | "@jest/globals": "^28.1.0", | ||
13 | "type-fest": "^2.13.0" | 14 | "type-fest": "^2.13.0" |
15 | }, | ||
16 | "devDependencies": { | ||
17 | "@jest/types": "^28.1.0" | ||
14 | } | 18 | } |
15 | } | 19 | } |
diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index 52ac98d..528b872 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts | |||
@@ -18,8 +18,7 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | ||
22 | eslint-disable-next-line import/prefer-default-export -- | ||
23 | Keep API consistent for more helpers in the future. | ||
24 | */ | ||
25 | export { default as fake } from './fake.js'; | 21 | export { default as fake } from './fake.js'; |
22 | |||
23 | export type { TestIf, TestIfConcurrent } from './testIf.js'; | ||
24 | export { default as testIf } from './testIf.js'; | ||
diff --git a/packages/test-utils/src/testIf.ts b/packages/test-utils/src/testIf.ts new file mode 100644 index 0000000..2309ddc --- /dev/null +++ b/packages/test-utils/src/testIf.ts | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | import { test } from '@jest/globals'; | ||
22 | import type { Global } from '@jest/types'; | ||
23 | |||
24 | export interface TestIfConcurrent { | ||
25 | (condition: boolean): Global.ItConcurrentBase; | ||
26 | |||
27 | only(condition: boolean): Global.ItConcurrentBase; | ||
28 | |||
29 | skip(condition: boolean): Global.ItConcurrentBase; | ||
30 | } | ||
31 | |||
32 | export interface TestIf { | ||
33 | (condition: boolean): Global.ItBase; | ||
34 | |||
35 | only(condition: boolean): Global.ItBase; | ||
36 | |||
37 | skip(condition: boolean): Global.ItBase; | ||
38 | |||
39 | concurrent: TestIfConcurrent; | ||
40 | } | ||
41 | |||
42 | const testIfConcurrent: TestIfConcurrent = function concurrent( | ||
43 | condition: boolean, | ||
44 | ) { | ||
45 | return condition ? test.concurrent : test.concurrent.skip; | ||
46 | }; | ||
47 | |||
48 | testIfConcurrent.only = function only() { | ||
49 | return test.concurrent.only; | ||
50 | }; | ||
51 | |||
52 | testIfConcurrent.skip = function skip() { | ||
53 | return test.concurrent.skip; | ||
54 | }; | ||
55 | |||
56 | const testIf: TestIf = function testIf(condition: boolean) { | ||
57 | return condition ? test : test.skip; | ||
58 | }; | ||
59 | |||
60 | testIf.only = function only() { | ||
61 | return test.only; | ||
62 | }; | ||
63 | |||
64 | testIf.skip = function skip() { | ||
65 | return test.skip; | ||
66 | }; | ||
67 | |||
68 | testIf.concurrent = testIfConcurrent; | ||
69 | |||
70 | export default testIf; | ||
@@ -1434,6 +1434,8 @@ __metadata: | |||
1434 | version: 0.0.0-use.local | 1434 | version: 0.0.0-use.local |
1435 | resolution: "@sophie/test-utils@workspace:packages/test-utils" | 1435 | resolution: "@sophie/test-utils@workspace:packages/test-utils" |
1436 | dependencies: | 1436 | dependencies: |
1437 | "@jest/globals": ^28.1.0 | ||
1438 | "@jest/types": ^28.1.0 | ||
1437 | type-fest: ^2.13.0 | 1439 | type-fest: ^2.13.0 |
1438 | languageName: unknown | 1440 | languageName: unknown |
1439 | linkType: soft | 1441 | linkType: soft |