-
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.
- **New Features** - Enhanced testing configurations and setups for improved development practices. - Improved module import system for better reliability and maintenance. - Implemented dependency injection in class functionalities for enhanced testability and modularity. - **Bug Fixes** - Implemented checks to prevent operations on empty tags and ensure proper logging in specific methods. - **Tests** - Introduced comprehensive test suites for key classes to ensure robustness and functionality integrity. - **Refactor** - Modified constructors in several classes to adhere to dependency injection principles. - **Documentation** - Updated project settings and configurations to align with new development tools and practices.
- Loading branch information
Showing
14 changed files
with
2,348 additions
and
37 deletions.
There are no files selected for viewing
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,5 @@ | ||
{ | ||
"jest.jestCommandLine": "yarn jest", | ||
"jest.rootPath": "src", | ||
"favorites.resources": [] | ||
} |
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,12 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
clearMocks: true, | ||
preset: 'ts-jest', | ||
moduleDirectories: ['node_modules'], | ||
moduleNameMapper: { | ||
'^@/(.*)$': '<rootDir>/src/$1', | ||
'^@model/(.*)$': '<rootDir>/src/model/$1', | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/tests/setup-tests.ts'], | ||
maxWorkers: 8, | ||
}; |
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,8 @@ | ||
import { jest } from '@jest/globals'; | ||
|
||
jest.mock('@actions/core', () => ({ | ||
startGroup: jest.fn(), | ||
endGroup: jest.fn(), | ||
info: jest.fn(), | ||
setFailed: jest.fn(), | ||
})); |
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,148 @@ | ||
import type { SimpleGit } from 'simple-git'; | ||
import type { Tags } from '@model/tags'; | ||
import type { getInput } from '@actions/core'; | ||
|
||
import { it, jest, describe, expect } from '@jest/globals'; | ||
import { exec } from '@actions/exec'; | ||
import { fromPartial } from '@total-typescript/shoehorn'; | ||
import { Configuration } from '@/configuration'; | ||
import { Artifacts } from '@model/artifacts'; | ||
|
||
jest.mock('@actions/exec', () => ({ | ||
__esModule: true, | ||
exec: jest.fn(), | ||
})); | ||
|
||
jest.mock('@model/tags', () => ({ | ||
__esModule: true, | ||
Tags: { | ||
collect: jest.fn(), | ||
move: jest.fn(), | ||
}, | ||
})); | ||
|
||
describe('Artifacts', () => { | ||
it('Compile the assets and Deploy when finished', async () => { | ||
const git = fromPartial<SimpleGit>({ | ||
commit: jest.fn(() => | ||
Promise.resolve({ summary: { changes: 0, insertions: 0, deletions: 0 } }) | ||
), | ||
push: jest.fn(() => | ||
Promise.resolve({ | ||
remoteMessages: { | ||
all: [''], | ||
}, | ||
}) | ||
), | ||
}); | ||
const tags = fromPartial<Tags>({ collect: jest.fn(), move: jest.fn() }); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(0)); | ||
|
||
await artifacts.update(); | ||
|
||
expect(jest.mocked(exec)).toHaveBeenNthCalledWith(1, 'yarn build'); | ||
expect(jest.mocked(exec)).toHaveBeenNthCalledWith(2, 'git add -f ./build/*'); | ||
}); | ||
|
||
it('Throw an error when failing to compile', async () => { | ||
const tags = fromPartial<Tags>({}); | ||
const git = fromPartial<SimpleGit>({}); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(1)); | ||
|
||
await expect(artifacts.update()).rejects.toThrow( | ||
'Failed creating artifacts: Failing to compile artifacts. Process exited with non-zero code.' | ||
); | ||
}); | ||
|
||
it('Throw an error when artifacts commit fails', async () => { | ||
const git = fromPartial<SimpleGit>({ | ||
commit: jest.fn(() => Promise.reject(new Error('Failed to commit'))), | ||
}); | ||
const tags = fromPartial<Tags>({ collect: jest.fn() }); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(0)); | ||
|
||
await expect(artifacts.update()).rejects.toThrow('Failed creating artifacts: Failed to commit'); | ||
}); | ||
|
||
it('Throw an error when artifacts push fails', async () => { | ||
const git = fromPartial<SimpleGit>({ | ||
commit: jest.fn(() => | ||
Promise.resolve({ summary: { changes: 0, insertions: 0, deletions: 0 } }) | ||
), | ||
push: jest.fn(() => Promise.reject(new Error('Failed to push'))), | ||
}); | ||
const tags = fromPartial<Tags>({ collect: jest.fn() }); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(0)); | ||
|
||
await expect(artifacts.update()).rejects.toThrow('Failed creating artifacts: Failed to push'); | ||
}); | ||
|
||
it('Throw an error when failing to git-add', async () => { | ||
const git = fromPartial<SimpleGit>({}); | ||
const tags = fromPartial<Tags>({ collect: jest.fn() }); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async (command) => (command === 'yarn build' ? 0 : 1)); | ||
|
||
await expect(artifacts.update()).rejects.toThrow( | ||
'Failed creating artifacts: Failing to git-add the artifacts build. Process exited with non-zero code.' | ||
); | ||
}); | ||
|
||
it('Throw an error when collecting tags fails', () => { | ||
const git = fromPartial<SimpleGit>({}); | ||
const tags = fromPartial<Tags>({ | ||
collect: jest.fn(() => Promise.reject(new Error('Failed to collect tags'))), | ||
}); | ||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(0)); | ||
|
||
expect(artifacts.update()).rejects.toThrow('Failed creating artifacts: Failed to collect tags'); | ||
}); | ||
|
||
it('Collect tags before moving them', async () => { | ||
const git = fromPartial<SimpleGit>({ | ||
commit: jest.fn(() => | ||
Promise.resolve({ summary: { changes: 0, insertions: 0, deletions: 0 } }) | ||
), | ||
push: jest.fn(() => | ||
Promise.resolve({ | ||
remoteMessages: { | ||
all: [''], | ||
}, | ||
}) | ||
), | ||
}); | ||
|
||
const collect = jest.fn(); | ||
const move = jest.fn(); | ||
const tags = fromPartial<Tags>({ collect, move }); | ||
|
||
const artifacts = new Artifacts(git, tags, configuration()); | ||
|
||
jest.mocked(exec).mockImplementation(async () => Promise.resolve(0)); | ||
|
||
await artifacts.update(); | ||
|
||
expect(collect.mock.invocationCallOrder[0]).toBeLessThan(move.mock.invocationCallOrder[0] ?? 0); | ||
}); | ||
}); | ||
|
||
function configuration(): Configuration { | ||
return new Configuration(stubGetInput()); | ||
} | ||
|
||
function stubGetInput(): typeof getInput { | ||
return jest.fn((name: string): string => { | ||
return name === 'command' ? 'yarn build' : './build'; | ||
}); | ||
} |
Oops, something went wrong.