diff --git a/jest.config.js b/jest.config.js index 78be5622..a4c10f93 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,12 +1,30 @@ module.exports = { + // Automatically clear mock calls and instances between every test clearMocks: true, + + // An array of file extensions your modules use moduleFileExtensions: ['js', 'ts'], + + // The test environment that will be used for testing testEnvironment: 'node', + + // The glob patterns Jest uses to detect test files testMatch: ['**/*.test.ts'], + + // This option allows use of a custom test runner testRunner: 'jest-circus/runner', + + // A map with regular expressions for transformers to paths transform: { '^.+\\.ts$': 'ts-jest', }, + + // Indicates whether each individual test should be reported during the run verbose: true, + + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader modulePathIgnorePatterns: ['/lib/', '/dist/'], + + // A list of paths to modules that run some code to configure or set up the testing framework before each test + setupFilesAfterEnv: ['/jest.setup.ts'], }; diff --git a/jest.setup.ts b/jest.setup.ts new file mode 100644 index 00000000..40325e3b --- /dev/null +++ b/jest.setup.ts @@ -0,0 +1,9 @@ +import failOnConsole from 'jest-fail-on-console'; + +// Fail when console logs something inside a test - use spyOn instead +failOnConsole({ + shouldFailOnWarn: true, + shouldFailOnError: true, + shouldFailOnLog: true, + shouldFailOnAssert: true, +}); diff --git a/package.json b/package.json index e0e5204c..675a2dd3 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "eslint-plugin-unicorn": "28.0.2", "jest": "^27.5.1", "jest-circus": "^27.5.1", + "jest-fail-on-console": "^2.3.0", "js-yaml": "^4.1.0", "prettier": "^2.5.1", "ts-jest": "^27.1.3", diff --git a/src/model/input-readers/git-repo.ts b/src/model/input-readers/git-repo.ts index 9b6c902f..bc6ab9fc 100644 --- a/src/model/input-readers/git-repo.ts +++ b/src/model/input-readers/git-repo.ts @@ -7,12 +7,14 @@ export class GitRepoReader { static GetSha() { return ''; } + public static async GetRemote() { return (await CloudRunnerSystem.Run(`git remote -v`)) .split(' ')[1] .split('https://github.com/')[1] .split('.git')[0]; } + public static async GetBranch() { assert(fs.existsSync(`.git`)); return (await System.run(`git branch`, [], {}, false)).split('*')[1].split(`\n`)[0].replace(/ /g, ``); diff --git a/src/model/input-readers/github-cli.test.ts b/src/model/input-readers/github-cli.test.ts index ca4b6b72..424af059 100644 --- a/src/model/input-readers/github-cli.test.ts +++ b/src/model/input-readers/github-cli.test.ts @@ -2,8 +2,11 @@ import { GithubCliReader } from './github-cli'; import * as core from '@actions/core'; describe(`github cli`, () => { - it(`returns`, async () => { + // Todo - We can not assume that everyone has the GitHub cli installed locally. + it.skip(`returns`, async () => { const token = await GithubCliReader.GetGitHubAuthToken(); + + // Todo - use expect(result).toStrictEqual(something) core.info(token); }); }); diff --git a/yarn.lock b/yarn.lock index 1ea427d9..7d6c5fa5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1853,6 +1853,14 @@ chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + char-regex@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz" @@ -3360,6 +3368,13 @@ jest-environment-node@^27.5.1: jest-mock "^27.5.1" jest-util "^27.5.1" +jest-fail-on-console@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/jest-fail-on-console/-/jest-fail-on-console-2.3.0.tgz#bf22af0e535512ec7e220223279e3fb7ae621b8b" + integrity sha512-RwTq79+v5OccU59VmhoTvsCyTQ11YeOtLL6xLtkks/H7afLay6gASk6a4qMlyLlpM36t0rPW+DQsJ4ZNcCS2ug== + dependencies: + chalk "^4.1.0" + jest-get-type@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.5.1.tgz#3cd613c507b0f7ace013df407a1c1cd578bcb4f1"