mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-09-09 06:14:10 +07:00
Fix matchers and add tests
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
import * as install from '../src/install';
|
||||
import * as matchers from '../src/matchers';
|
||||
import * as path from 'path';
|
||||
|
||||
/**
|
||||
* Mock install.ts
|
||||
@ -152,34 +150,4 @@ describe('Install', () => {
|
||||
expect(script).toContain('set coverage driver');
|
||||
expect(script).toContain('sh script.sh 7.3 ' + __dirname);
|
||||
});
|
||||
|
||||
describe('Matchers', () => {
|
||||
let originalLogMethod: any;
|
||||
let outputData: any[] = [];
|
||||
|
||||
beforeAll(() => {
|
||||
originalLogMethod = console.log;
|
||||
console['log'] = jest.fn(inputs => outputData.push(inputs));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
outputData = [];
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
console['log'] = originalLogMethod;
|
||||
});
|
||||
|
||||
it('Add matchers', async () => {
|
||||
matchers.addMatchers();
|
||||
|
||||
expect(outputData).toEqual([
|
||||
`##[add-matcher]${path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'.github/matchers/phpunit.json'
|
||||
)}`
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
34
__tests__/matchers.test.ts
Normal file
34
__tests__/matchers.test.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import * as io from '@actions/io';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as matchers from '../src/matchers';
|
||||
|
||||
async function cleanup(path: string): Promise<void> {
|
||||
fs.unlink(path, error => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jest.mock('@actions/io');
|
||||
|
||||
describe('Matchers', () => {
|
||||
it('Add matchers', async () => {
|
||||
process.env['RUNNER_TOOL_CACHE'] = __dirname;
|
||||
await matchers.addMatchers();
|
||||
const spy = jest.spyOn(io, 'cp');
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('Test Regex', async () => {
|
||||
const regex1 = /^\d+\)\s.*$/;
|
||||
const regex2 = /^(.*)$/;
|
||||
const regex3 = /^\s*$/;
|
||||
const regex4 = /^(.*):(\d+)$/;
|
||||
expect(regex1.test('1) Tests\\Test::it_tests')).toBe(true);
|
||||
expect(regex2.test('Failed asserting that false is true')).toBe(true);
|
||||
expect(regex3.test('\n')).toBe(true);
|
||||
expect(regex4.test('/path/to/file.php:42')).toBe(true);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user