Skip to content

Commit

Permalink
configure editor for match prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
smac89 committed Nov 21, 2023
1 parent 8bf8b81 commit 2bc0c40
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 64 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true,
"files.associations": {
".*rc": "json"
".importsortrc": "json"
}
}
85 changes: 37 additions & 48 deletions tests/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ describe('Functions', () => {
])('#getPreferredRef()', ({ preferbranchReleases, expected }) => {
test(`when INPUT_PREFER_BRANCH_RELEASES=${preferbranchReleases} returns ${expected}`, async () => {
process.env.INPUT_PREFER_BRANCH_RELEASES = preferbranchReleases;
await import('@actionstagger/functions/public').then(
({ default: { getPreferredRef } }) =>
expect(getPreferredRef()).toBe(expected)
await import('@actionstagger/functions/public').then(({ default: { getPreferredRef } }) =>
expect(getPreferredRef()).toBe(expected)
);
});
});
Expand All @@ -34,38 +33,35 @@ describe('Functions', () => {
githubRef: 'refs/heads/v2.3.0',
expected: '2.3.0',
},
])(
'#getPublishRefVersion()',
({ eventName, preferbranchReleases, githubRef, expected }) => {
const dir = fs.mkdtempSync(os.tmpdir() + '/jest-push');
])('#getPublishRefVersion()', ({ eventName, preferbranchReleases, githubRef, expected }) => {
const dir = fs.mkdtempSync(os.tmpdir() + '/jest-push');

beforeEach(() => {
const pushEvent = {
ref: `${githubRef}`,
created: true,
};
fs.writeFileSync(`${dir}/event.json`, JSON.stringify(pushEvent));
process.env.GITHUB_EVENT_PATH = `${dir}/event.json`;
process.env.INPUT_PREFER_BRANCH_RELEASES = preferbranchReleases;
process.env.GITHUB_EVENT_NAME = eventName;
process.env.GITHUB_REF_NAME = githubRef.replace(/refs\/.+\//g, '');
process.env.GITHUB_REF = githubRef;
});
beforeEach(() => {
const pushEvent = {
ref: `${githubRef}`,
created: true,
};
fs.writeFileSync(`${dir}/event.json`, JSON.stringify(pushEvent));
process.env.GITHUB_EVENT_PATH = `${dir}/event.json`;
process.env.INPUT_PREFER_BRANCH_RELEASES = preferbranchReleases;
process.env.GITHUB_EVENT_NAME = eventName;
process.env.GITHUB_REF_NAME = githubRef.replace(/refs\/.+\//g, '');
process.env.GITHUB_REF = githubRef;
});

afterEach(() => {
fs.rmSync(dir, { recursive: true });
// actions toolkit tries to read this file if it is set, which we don't want
delete process.env.GITHUB_EVENT_PATH;
});
afterEach(() => {
fs.rmSync(dir, { recursive: true });
// actions toolkit tries to read this file if it is set, which we don't want
delete process.env.GITHUB_EVENT_PATH;
});

test(`on ${eventName} when INPUT_PREFER_BRANCH_RELEASES=${preferbranchReleases}, pushed ref=${githubRef}, returns=${expected}`, async () => {
await import('@actionstagger/functions/public').then(
({ default: { getPublishRefVersion } }) =>
expect(getPublishRefVersion().version).toBe(expected)
);
});
}
);
test(`on ${eventName} when INPUT_PREFER_BRANCH_RELEASES=${preferbranchReleases}, pushed ref=${githubRef}, returns=${expected}`, async () => {
await import('@actionstagger/functions/public').then(
({ default: { getPublishRefVersion } }) =>
expect(getPublishRefVersion().version).toBe(expected)
);
});
});

describe.each([
{
Expand Down Expand Up @@ -125,10 +121,7 @@ describe('Functions', () => {
},
])('#findLatestRef()', ({ pushedRef, existing, repoLatest, expected }) => {
const octokit = getOctokit('TEST_TOKEN');
const refsList: GraphQlQueryRepository['refs']['refsList'] = [
existing,
repoLatest,
]
const refsList: GraphQlQueryRepository['refs']['refsList'] = [existing, repoLatest]
.filter((ref): ref is string => Boolean(ref))
.map((version, i) => ({
ref: {
Expand All @@ -140,17 +133,13 @@ describe('Functions', () => {
}));

beforeEach(async () => {
const semverTag = (await import('semver/functions/parse')).default(
pushedRef
);
const semverTag = (await import('semver/functions/parse')).default(pushedRef);

jest.doMock('@actionstagger/functions/public', () => {
const MockFunctions = jest.requireActual<
typeof import('@actionstagger/functions/public')
>('@actionstagger/functions/public').default;
MockFunctions.getPublishRefVersion = jest
.fn()
.mockReturnValue(semverTag);
const MockFunctions = jest.requireActual<typeof import('@actionstagger/functions/public')>(
'@actionstagger/functions/public'
).default;
MockFunctions.getPublishRefVersion = jest.fn().mockReturnValue(semverTag);
return {
__esModule: true,
default: MockFunctions,
Expand All @@ -160,9 +149,9 @@ describe('Functions', () => {

test(`when new release or push of ${pushedRef}, and ref with name ${
existing ?? 'unknown'
} exists and latest ref is ${
repoLatest ?? 'unknown'
}, returns [${expected.join(', ')}]`, async () => {
} exists and latest ref is ${repoLatest ?? 'unknown'}, returns [${expected.join(
', '
)}]`, async () => {
const spyOctokit = jest.spyOn(octokit, 'graphql').mockResolvedValue(
Promise.resolve<{ repository: GraphQlQueryRepository }>({
repository: {
Expand Down
5 changes: 1 addition & 4 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
"module": "commonjs",
"moduleResolution": "Node"
},
"include": [
"*.ts",
"../index.d.ts"
]
"include": ["*.ts", "../index.d.ts"]
}
14 changes: 3 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@
"noUnusedLocals": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@actionstagger/*": [
"./src/*"
],
"@actionstagger": [
"./src"
]
"@actionstagger/*": ["./src/*"],
"@actionstagger": ["./src"]
}
},
"include": [
"src/**/*.ts",
"jest.config.ts",
"index.d.ts"
]
"include": ["src/**/*.ts", "jest.config.ts", "index.d.ts"]
}

0 comments on commit 2bc0c40

Please sign in to comment.