Skip to content

Commit f06af33

Browse files
committed
Add tests
1 parent 52ffa4b commit f06af33

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

test/__snapshots__/cli.spec.js.snap

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
exports[`prettier-formatter-gitlab cli should create a code quality report file with prettier -l 1`] = `
44
[
5+
{
6+
"check_name": "prettier",
7+
"description": "Delete ⏎",
8+
"fingerprint": "994d9053d8e5f73c098f2bcfadec786c",
9+
"location": {
10+
"lines": {
11+
"begin": 11,
12+
"end": 12,
13+
},
14+
"path": "test/__stubs__/.gitlab-ci.fail.yml",
15+
},
16+
"severity": "minor",
17+
"type": "issue",
18+
},
519
{
620
"check_name": "prettier",
721
"description": "Delete ⏎",
@@ -96,6 +110,20 @@ exports[`prettier-formatter-gitlab cli should create a code quality report file
96110
97111
exports[`prettier-formatter-gitlab cli should create a code quality report file with prettier -c 1`] = `
98112
[
113+
{
114+
"check_name": "prettier",
115+
"description": "Delete ⏎",
116+
"fingerprint": "994d9053d8e5f73c098f2bcfadec786c",
117+
"location": {
118+
"lines": {
119+
"begin": 11,
120+
"end": 12,
121+
},
122+
"path": "test/__stubs__/.gitlab-ci.fail.yml",
123+
},
124+
"severity": "minor",
125+
"type": "issue",
126+
},
99127
{
100128
"check_name": "prettier",
101129
"description": "Delete ⏎",

test/__stubs__/.gitlab-ci.fail.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.ref:
2+
script:
3+
- npm run lint
4+
5+
prettier:
6+
script:
7+
- !reference [.ref, script]
8+
artifacts:
9+
reports:
10+
codequalit: gl-codequality.json
11+

test/utils/get-output-path.spec.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
import { describe, it, expect } from 'bun:test';
1+
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
22
import { resolve, join } from 'node:path';
33
import { getOutputPath } from '../../src/utils/get-output-path.js';
44

5+
let env;
6+
7+
beforeEach(() => {
8+
env = process.env;
9+
});
10+
11+
afterEach(() => {
12+
process.env = env;
13+
});
14+
515
describe('The getPrettierFileInfos function', () => {
616
it('should return the output path defined in a .gitlab-ci.yml file', () => {
717
process.env.CI_PROJECT_DIR = resolve(join(import.meta.dirname, '../__stubs__/'));
@@ -11,4 +21,16 @@ describe('The getPrettierFileInfos function', () => {
1121
resolve(join(import.meta.dirname, '../__stubs__/gl-codequality.json')),
1222
);
1323
});
24+
25+
it('should throw an error if it can not find the report file path', () => {
26+
process.env.CI_PROJECT_DIR = resolve(join(import.meta.dirname, '../__stubs__/'));
27+
process.env.CI_JOB_NAME = 'prettier';
28+
process.env.CI_CONFIG_PATH = '.gitlab-ci.fail.yml';
29+
expect(getOutputPath).toThrow();
30+
});
31+
32+
it('should throw an error if it can not find a .gitlab-ci.yml file', () => {
33+
process.env.CI_PROJECT_DIR = '/tmp';
34+
expect(getOutputPath).toThrow();
35+
});
1436
});

0 commit comments

Comments
 (0)