Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Jan 25, 2025
1 parent 52ffa4b commit f06af33
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
28 changes: 28 additions & 0 deletions test/__snapshots__/cli.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

exports[`prettier-formatter-gitlab cli should create a code quality report file with prettier -l 1`] = `
[
{
"check_name": "prettier",
"description": "Delete ⏎",
"fingerprint": "994d9053d8e5f73c098f2bcfadec786c",
"location": {
"lines": {
"begin": 11,
"end": 12,
},
"path": "test/__stubs__/.gitlab-ci.fail.yml",
},
"severity": "minor",
"type": "issue",
},
{
"check_name": "prettier",
"description": "Delete ⏎",
Expand Down Expand Up @@ -96,6 +110,20 @@ exports[`prettier-formatter-gitlab cli should create a code quality report file
exports[`prettier-formatter-gitlab cli should create a code quality report file with prettier -c 1`] = `
[
{
"check_name": "prettier",
"description": "Delete ⏎",
"fingerprint": "994d9053d8e5f73c098f2bcfadec786c",
"location": {
"lines": {
"begin": 11,
"end": 12,
},
"path": "test/__stubs__/.gitlab-ci.fail.yml",
},
"severity": "minor",
"type": "issue",
},
{
"check_name": "prettier",
"description": "Delete ⏎",
Expand Down
11 changes: 11 additions & 0 deletions test/__stubs__/.gitlab-ci.fail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.ref:
script:
- npm run lint

prettier:
script:
- !reference [.ref, script]
artifacts:
reports:
codequalit: gl-codequality.json

24 changes: 23 additions & 1 deletion test/utils/get-output-path.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { describe, it, expect } from 'bun:test';
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
import { resolve, join } from 'node:path';
import { getOutputPath } from '../../src/utils/get-output-path.js';

let env;

beforeEach(() => {
env = process.env;
});

afterEach(() => {
process.env = env;
});

describe('The getPrettierFileInfos function', () => {
it('should return the output path defined in a .gitlab-ci.yml file', () => {
process.env.CI_PROJECT_DIR = resolve(join(import.meta.dirname, '../__stubs__/'));
Expand All @@ -11,4 +21,16 @@ describe('The getPrettierFileInfos function', () => {
resolve(join(import.meta.dirname, '../__stubs__/gl-codequality.json')),
);
});

it('should throw an error if it can not find the report file path', () => {
process.env.CI_PROJECT_DIR = resolve(join(import.meta.dirname, '../__stubs__/'));
process.env.CI_JOB_NAME = 'prettier';
process.env.CI_CONFIG_PATH = '.gitlab-ci.fail.yml';
expect(getOutputPath).toThrow();
});

it('should throw an error if it can not find a .gitlab-ci.yml file', () => {
process.env.CI_PROJECT_DIR = '/tmp';
expect(getOutputPath).toThrow();
});
});

0 comments on commit f06af33

Please sign in to comment.