forked from game-ci/unity-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to streamline dev lifecycle (git hooks) (game-ci#357)
* fix: misalignments in dev lifecycle * fix: dist no longer added to staged * fix: misalignments in dev lifecycle * chore: multi-platform hooks and tests * chore: multi-platform hooks and tests * chore: add intention for colors * chore: update lint-staged to fix color * chore: update dist files * feat: move to lefthook (remove husky and lint-staged) * feat: move to lefthook (remove husky and lint-staged) * fix: test aftereach * fix: test aftereach * fix: early restore call * feat: jest fails if something gets logged to console * chore: add todos of misplaced code * chore: update dist files * chore: move jest file
- Loading branch information
1 parent
9440c54
commit f1c154a
Showing
17 changed files
with
4,790 additions
and
4,878 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +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: ['<rootDir>/lib/', '<rootDir>/dist/'], | ||
|
||
// A list of paths to modules that run some code to configure or set up the testing framework before each test | ||
setupFilesAfterEnv: ['<rootDir>/src/jest.setup.ts'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# EXAMPLE USAGE | ||
# Refer for explanation to following link: | ||
# https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md | ||
# | ||
|
||
color: true | ||
extends: {} | ||
|
||
pre-push: | ||
parallel: true | ||
commands: | ||
packages-audit: | ||
tags: security | ||
run: yarn audit | ||
|
||
pre-commit: | ||
parallel: true | ||
commands: | ||
format documents: | ||
glob: '*.{md,mdx}' | ||
run: yarn prettier --write {staged_files} | ||
format configs: | ||
glob: '*.{json,yml,yaml}' | ||
run: yarn prettier --write {staged_files} | ||
format code: | ||
glob: '*.{js,jsx,ts,tsx}' | ||
exclude: 'dist/' | ||
run: yarn prettier --write {staged_files} && yarn eslint {staged_files} && git add {staged_files} | ||
run tests: | ||
glob: '*.{js,jsx,ts,tsx}' | ||
exclude: 'dist/' | ||
run: yarn jest --passWithNoTests --findRelatedTests {staged_files} | ||
build distributables: | ||
skip: ['merge', 'rebase'] | ||
run: yarn build && git add dist | ||
make shell script executable: | ||
glob: '*.sh' | ||
run: git update-index --chmod=+x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,10 @@ | |
"author": "Webber <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"prebuild": "yarn", | ||
"build": "tsc && ncc build lib --source-map --license licenses.txt", | ||
"prepare": "lefthook install", | ||
"build": "yarn && tsc && ncc build lib --source-map --license licenses.txt", | ||
"lint": "prettier --check \"src/**/*.{js,ts}\" && eslint src/**/*.ts", | ||
"format": "prettier --write \"src/**/*.{js,ts}\"", | ||
"prepare": "husky install", | ||
"cli": "yarn ts-node src/index.ts -m cli", | ||
"cli-aws": "cross-env cloudRunnerCluster=aws yarn run test-cli", | ||
"cli-k8s": "cross-env cloudRunnerCluster=k8s yarn run test-cli", | ||
|
@@ -41,6 +40,7 @@ | |
"yaml": "^1.10.2" | ||
}, | ||
"devDependencies": { | ||
"@arkweid/lefthook": "^0.7.7", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.21", | ||
"@types/semver": "^7.3.9", | ||
|
@@ -53,27 +53,13 @@ | |
"eslint-plugin-jest": "24.1.3", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint-plugin-unicorn": "28.0.2", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"jest-circus": "^27.5.1", | ||
"jest-fail-on-console": "^2.3.0", | ||
"js-yaml": "^4.1.0", | ||
"lint-staged": "^12.3.4", | ||
"prettier": "^2.5.1", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "10.4.0", | ||
"typescript": "4.1.3" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx}": [ | ||
"prettier --write", | ||
"eslint", | ||
"jest --findRelatedTests" | ||
], | ||
"*.{json,md,yaml,yml}": [ | ||
"prettier --write" | ||
], | ||
"*.sh": [ | ||
"git update-index --chmod=+x" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as core from '@actions/core'; | ||
import System from './system'; | ||
|
||
jest.spyOn(core, 'debug').mockImplementation(() => {}); | ||
jest.spyOn(core, 'info').mockImplementation(() => {}); | ||
jest.spyOn(core, 'warning').mockImplementation(() => {}); | ||
jest.spyOn(core, 'error').mockImplementation(() => {}); | ||
|
||
afterEach(() => jest.clearAllMocks()); | ||
|
||
describe('System', () => { | ||
describe('run', () => { | ||
/** | ||
* Not all shells (e.g. Powershell, sh) have a reference to `echo` binary (absent or alias). | ||
* To ensure our integration with '@actions/exec' works as expected we run some specific tests in CI only | ||
*/ | ||
describe('integration', () => { | ||
if (!process.env.CI) { | ||
it("doesn't run locally", () => { | ||
expect(true).toBe(true); | ||
}); | ||
} else { | ||
it('runs a command successfully', async () => { | ||
await expect(System.run('true')).resolves.not.toBeNull(); | ||
}); | ||
|
||
it('outputs results', async () => { | ||
await expect(System.run('echo test')).resolves.toStrictEqual('test\n'); | ||
}); | ||
|
||
it('throws on when error code is not 0', async () => { | ||
await expect(System.run('false')).rejects.toThrowError(); | ||
}); | ||
|
||
it('allows pipes using buffer', async () => { | ||
await expect( | ||
System.run('sh', undefined, { | ||
input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'), | ||
// eslint-disable-next-line github/no-then | ||
}).then((result) => Number(result)), | ||
).resolves.not.toBeNaN(); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,46 @@ | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
import System from './system'; | ||
|
||
jest.spyOn(core, 'debug').mockImplementation(() => {}); | ||
const info = jest.spyOn(core, 'info').mockImplementation(() => {}); | ||
jest.spyOn(core, 'warning').mockImplementation(() => {}); | ||
jest.spyOn(core, 'error').mockImplementation(() => {}); | ||
const execSpy = jest.spyOn(exec, 'exec').mockImplementation(async () => 0); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
afterEach(() => jest.clearAllMocks()); | ||
|
||
describe('System', () => { | ||
describe('run', () => { | ||
it('runs a command successfully', async () => { | ||
await expect(System.run('true')).resolves.not.toBeNull(); | ||
}); | ||
|
||
it('outputs results', async () => { | ||
await expect(System.run('echo test')).resolves.toStrictEqual('test\n'); | ||
}); | ||
|
||
it('throws on when error code is not 0', async () => { | ||
await expect(System.run('false')).rejects.toThrowError(); | ||
}); | ||
|
||
it('throws when no arguments are given', async () => { | ||
await expect(System.run('')).rejects.toThrowError(); | ||
}); | ||
|
||
it('outputs info', async () => { | ||
await expect(System.run('echo test')).resolves.not.toBeNull(); | ||
expect(info).toHaveBeenLastCalledWith('test\n'); | ||
}); | ||
|
||
it('outputs info only once', async () => { | ||
await expect(System.run('echo 1')).resolves.not.toBeNull(); | ||
expect(info).toHaveBeenCalledTimes(1); | ||
expect(info).toHaveBeenLastCalledWith('1\n'); | ||
|
||
info.mockClear(); | ||
await expect(System.run('echo 2')).resolves.not.toBeNull(); | ||
await expect(System.run('echo 3')).resolves.not.toBeNull(); | ||
expect(info).toHaveBeenCalledTimes(2); | ||
expect(info).toHaveBeenLastCalledWith('3\n'); | ||
}); | ||
|
||
it('allows pipes using buffer', async () => { | ||
await expect( | ||
System.run('sh', undefined, { | ||
input: Buffer.from('git tag --list --merged HEAD | grep v[0-9]* | wc -l'), | ||
// eslint-disable-next-line github/no-then | ||
}).then((result) => Number(result)), | ||
).resolves.not.toBeNaN(); | ||
describe('units', () => { | ||
it('passes the command to command line', async () => { | ||
await expect(System.run('echo test')).resolves.not.toBeNull(); | ||
await expect(execSpy).toHaveBeenLastCalledWith('echo test', expect.anything(), expect.anything()); | ||
}); | ||
|
||
it('throws on when error code is not 0', async () => { | ||
execSpy.mockImplementationOnce(async () => 1); | ||
await expect(System.run('false')).rejects.toThrowError(); | ||
}); | ||
|
||
it('throws when no command is given', async () => { | ||
await expect(System.run('')).rejects.toThrowError(); | ||
}); | ||
|
||
it('throws when command consists only of spaces', async () => { | ||
await expect(System.run(' \t\n')).rejects.toThrowError(); | ||
}); | ||
|
||
it('outputs info', async () => { | ||
execSpy.mockImplementationOnce(async (input, _, options) => { | ||
options?.listeners?.stdout?.(Buffer.from(input, 'utf8')); | ||
return 0; | ||
}); | ||
|
||
await expect(System.run('foo-bar')).resolves.not.toBeNull(); | ||
expect(info).toHaveBeenCalledTimes(1); | ||
expect(info).toHaveBeenLastCalledWith('foo-bar'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.