test: async test -> sync

This commit is contained in:
Wataru Kurashima 2022-08-31 13:35:30 +09:00
parent 0cf6bc4d0e
commit 864dd31b7b
3 changed files with 10 additions and 9 deletions

View File

@ -52,7 +52,8 @@ describe('Utils tests', () => {
expect(await utils.parseVersion('4.x')).toBe(undefined);
});
it('checking resolveVersionInput', async () => {
it('checking resolveVersionInput', () => {
// composer.json
expect(utils.parsePhpVersionFile('{"require": {"php": "^8.1"}}')).toBe(
'8.1'
);
@ -68,6 +69,10 @@ describe('Utils tests', () => {
expect(utils.parsePhpVersionFile('{"require": {"php": "^8.1|^8.0"}}')).toBe(
'8.1'
);
// asdf: .tool-versions
expect(utils.parsePhpVersionFile('php 8.1')).toBe('8.1');
// phpenv: .php-version
expect(utils.parsePhpVersionFile('8.1.1')).toBe('8.1');
});
it('checking parseIniFile', async () => {

6
dist/index.js vendored
View File

@ -1070,10 +1070,8 @@ async function resolveVersionInput() {
}
exports.resolveVersionInput = resolveVersionInput;
function parsePhpVersionFile(contents) {
const json = JSON.parse(contents);
const version = json.config?.platform?.php ?? json.require?.php;
const match = version.match(/(\d+(\.\d+))/);
return match ? match[1] : '';
const match = contents.match(/("php:")?.*?(\d+(\.\d+))/);
return match ? match[2] : '';
}
exports.parsePhpVersionFile = parsePhpVersionFile;
async function getManifestURL() {

View File

@ -76,10 +76,8 @@ export async function resolveVersionInput(): Promise<string> {
}
export function parsePhpVersionFile(contents: string): string {
const json = JSON.parse(contents);
const version = json.config?.platform?.php ?? json.require?.php;
const match = version.match(/(\d+(\.\d+))/);
return match ? match[1] : '';
const match = contents.match(/("php:")?.*?(\d+(\.\d+))/);
return match ? match[2] : '';
}
/** Function to get manifest URL