zola-check-manager

A Github Action allowing you to manage the zola check results in github
git clone git://archive.git.mtrnord.blog/MTRNord/zola-check-manager.git
Log | Files | Refs | README | LICENSE

main.test.ts (3477B)


      1 import { test } from '@jest/globals';
      2 import { readFile, writeFile } from 'fs/promises';
      3 
      4 import path, { dirname } from 'node:path';
      5 import grammar from '../src/grammar.js';
      6 import nock from 'nock';
      7 import { fileURLToPath } from 'node:url';
      8 // @ts-ignore
      9 import nearly from 'nearley/lib/nearley.js';
     10 import { closeSync, openSync } from 'node:fs';
     11 const { Grammar, Parser } = nearly;
     12 
     13 const __dirname = dirname(fileURLToPath(import.meta.url));
     14 
     15 describe('parser test suite', () => {
     16   test('test parsing', async () => {
     17     const data: string = await readFile(
     18       path.join(__dirname, '/test_data.txt'),
     19       'utf8'
     20     );
     21     const parser: typeof Parser = new Parser(Grammar.fromCompiled(grammar));
     22     parser.feed(data);
     23     await writeFile(__dirname + '/parsed.json', JSON.stringify(parser.results));
     24     //expect(delta).toBeGreaterThan(450)
     25   });
     26 
     27   test('test stdoutparsing', async () => {
     28     const data: string = await readFile(
     29       path.join(__dirname, '/test_data_stdout.txt'),
     30       'utf8'
     31     );
     32     const parser: typeof Parser = new Parser(Grammar.fromCompiled(grammar));
     33     parser.feed(data);
     34     await writeFile(
     35       __dirname + '/parsed_stdout.json',
     36       JSON.stringify(parser.results)
     37     );
     38     //expect(delta).toBeGreaterThan(450)
     39   });
     40 
     41   test('test parsing with no faulty links', async () => {
     42     const data: string = await readFile(
     43       path.join(__dirname, '/test_data_stdout_no_error.txt'),
     44       'utf8'
     45     );
     46     const parser: typeof Parser = new Parser(Grammar.fromCompiled(grammar));
     47     parser.feed(data);
     48     await writeFile(
     49       __dirname + '/parsed_stdout_no_error.json',
     50       JSON.stringify(parser.results)
     51     );
     52 
     53     // Check if we parse an empty stderr successfully
     54     const stdErrParser: typeof Parser = new Parser(
     55       Grammar.fromCompiled(grammar)
     56     );
     57     stdErrParser.feed('');
     58     //expect(delta).toBeGreaterThan(450)
     59   });
     60 });
     61 
     62 describe('action test suite', () => {
     63   it('It generates checks for the broken link in the test_page folder', async () => {
     64     const workingDirectory = './test_page';
     65     const repoToken = 'token';
     66     const conclusion_level = 'neutral';
     67 
     68     process.env['INPUT_WORKING_DIRECTORY'] = workingDirectory;
     69     process.env['INPUT_CONCLUSION_LEVEL'] = conclusion_level;
     70     process.env['INPUT_REPO-TOKEN'] = repoToken;
     71 
     72     process.env['GITHUB_REPOSITORY'] = 'foo/bar';
     73     process.env['GITHUB_STEP_SUMMARY'] = path.join(__dirname, 'summary');
     74     process.env['GITHUB_SHA'] = '1234';
     75     closeSync(openSync(process.env['GITHUB_STEP_SUMMARY'], 'w'));
     76     process.env['GITHUB_EVENT_PATH'] = path.join(__dirname, 'payload.json');
     77     process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'tool_cache');
     78     process.env['RUNNER_TEMP'] = path.join(__dirname, 'tool_temp');
     79 
     80     nock('https://api.github.com')
     81       .persist()
     82       .post(
     83         '/repos/foo/bar/check-runs',
     84         '{"name":"Zola Check","head_sha":"1234","status":"completed","conclusion":"neutral","output":{"title":"Link is not reachable","summary":"Zola check found links which are not reachable. Make sure to either ignore these due to being false positives or fixing them","annotations":[{"path":"/test_page/content/blog/second.md","start_line":7,"end_line":7,"start_column":34,"end_column":63,"annotation_level":"","message":"Zola Error Message: Client error status code (404 Not Found) received"}]}}'
     85       )
     86       .reply(201);
     87 
     88     const main = await import('../src/main.js');
     89 
     90     await main.run();
     91   }, 10000);
     92 });