Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jest/recommended ESLint config #1222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 3 additions & 11 deletions .eslintrc.json
@@ -1,23 +1,15 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:jest/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.lint.json"
},
"globals": {
"fetch": true
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
"node": true
},
"rules": {
"@typescript-eslint/ban-types": [
Expand Down
4 changes: 2 additions & 2 deletions __tests__/execute.test.ts
Expand Up @@ -10,7 +10,7 @@ describe('execute', () => {
stdout('hello')
await execute('echo Montezuma', './', true)

expect(exec).toBeCalledWith('echo Montezuma', [], {
expect(exec).toHaveBeenCalledWith('echo Montezuma', [], {
cwd: './',
silent: true,
ignoreReturnCode: false,
Expand All @@ -27,7 +27,7 @@ describe('execute', () => {
stdout('hello')
await execute('echo Montezuma', './', false)

expect(exec).toBeCalledWith('echo Montezuma', [], {
expect(exec).toHaveBeenCalledWith('echo Montezuma', [], {
cwd: './',
silent: false,
ignoreReturnCode: false,
Expand Down
84 changes: 36 additions & 48 deletions __tests__/git.test.ts
Expand Up @@ -55,7 +55,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})

it('should catch when a function throws an error', async () => {
Expand All @@ -77,13 +77,9 @@ describe('git', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})

try {
await init(action)
} catch (error) {
expect(error instanceof Error && error.message).toBe(
'There was an error initializing the repository: Mocked throw ❌'
)
}
await expect(init(action)).rejects.toThrow(
'There was an error initializing the repository: Mocked throw ❌'
)
})

it('should correctly continue when it cannot unset a git config value', async () => {
Expand All @@ -102,7 +98,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})

it('should not unset git config if a user is using ssh', async () => {
Expand All @@ -124,7 +120,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(6)
expect(execute).toHaveBeenCalledTimes(6)

process.env.CI = undefined
})
Expand All @@ -145,7 +141,7 @@ describe('git', () => {
})

await init(action)
expect(execute).toBeCalledTimes(7)
expect(execute).toHaveBeenCalledTimes(7)
})
})

Expand All @@ -168,8 +164,8 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})

Expand All @@ -191,8 +187,8 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SUCCESS)
})

Expand All @@ -216,8 +212,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should execute commands with single commit toggled and existing branch', async () => {
Expand All @@ -240,8 +236,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should execute commands with single commit and dryRun toggled', async () => {
Expand All @@ -265,8 +261,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(13)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(13)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should not ignore CNAME or nojekyll if they exist in the deployment folder', async () => {
Expand Down Expand Up @@ -296,9 +292,9 @@ describe('git', () => {
const response = await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(14)
expect(rmRF).toBeCalledTimes(1)
expect(fs.existsSync).toBeCalledTimes(2)
expect(execute).toHaveBeenCalledTimes(14)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(fs.existsSync).toHaveBeenCalledTimes(2)
expect(response).toBe(Status.SUCCESS)
})

Expand Down Expand Up @@ -328,8 +324,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
})
})

Expand All @@ -353,8 +349,8 @@ describe('git', () => {
await deploy(action)

// Includes the call to generateWorktree
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
})

it('should gracefully handle target folder', async () => {
Expand All @@ -373,9 +369,9 @@ describe('git', () => {

await deploy(action)

expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(mkdirP).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(mkdirP).toHaveBeenCalledTimes(1)
})

it('should stop early if there is nothing to commit', async () => {
Expand All @@ -393,8 +389,8 @@ describe('git', () => {
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(11)
expect(rmRF).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(11)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(response).toBe(Status.SKIPPED)
})

Expand All @@ -416,13 +412,9 @@ describe('git', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})

try {
await deploy(action)
} catch (error) {
expect(error instanceof Error && error.message).toBe(
'The deploy step encountered an error: Mocked throw ❌'
)
}
await expect(deploy(action)).rejects.toThrow(
'The deploy step encountered an error: Mocked throw ❌'
)
})

it('should execute commands if force is false and retry until limit is exceeded', async () => {
Expand All @@ -441,13 +433,9 @@ describe('git', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})

try {
await deploy(action)
} catch (error) {
expect(error instanceof Error && error.message).toBe(
'The deploy step encountered an error: Attempt limit exceeded ❌'
)
}
await expect(deploy(action)).rejects.toThrow(
'The deploy step encountered an error: Attempt limit exceeded ❌'
)
})

it('should add a tag to the commit', async () => {
Expand All @@ -467,7 +455,7 @@ describe('git', () => {
})

const response = await deploy(action)
expect(execute).toBeCalledTimes(16)
expect(execute).toHaveBeenCalledTimes(16)
expect(response).toBe(Status.SUCCESS)
})
})
Expand Down
18 changes: 9 additions & 9 deletions __tests__/main.test.ts
Expand Up @@ -53,9 +53,9 @@ describe('main', () => {
debug: true
})
await run(action)
expect(execute).toBeCalledTimes(18)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(18)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})

it('should run through the commands and succeed', async () => {
Expand All @@ -73,9 +73,9 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(21)
expect(rmRF).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(21)
expect(rmRF).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})

it('should throw if an error is encountered', async () => {
Expand All @@ -92,8 +92,8 @@ describe('main', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})
await run(action)
expect(execute).toBeCalledTimes(0)
expect(setFailed).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(1)
expect(execute).toHaveBeenCalledTimes(0)
expect(setFailed).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(1)
})
})
28 changes: 12 additions & 16 deletions __tests__/ssh.test.ts
Expand Up @@ -57,9 +57,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execute).toBeCalledTimes(0)
expect(mkdirP).toBeCalledTimes(0)
expect(appendFileSync).toBeCalledTimes(0)
expect(execute).toHaveBeenCalledTimes(0)
expect(mkdirP).toHaveBeenCalledTimes(0)
expect(appendFileSync).toHaveBeenCalledTimes(0)
})

it('should configure the ssh client if a key is defined', async () => {
Expand All @@ -82,9 +82,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execFileSync).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(2)
expect(execSync).toBeCalledTimes(3)
expect(execFileSync).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(2)
expect(execSync).toHaveBeenCalledTimes(3)
})

it('should not export variables if the return from ssh-agent is skewed', async () => {
Expand All @@ -107,9 +107,9 @@ describe('configureSSH', () => {

await configureSSH(action)

expect(execFileSync).toBeCalledTimes(1)
expect(exportVariable).toBeCalledTimes(0)
expect(execSync).toBeCalledTimes(3)
expect(execFileSync).toHaveBeenCalledTimes(1)
expect(exportVariable).toHaveBeenCalledTimes(0)
expect(execSync).toHaveBeenCalledTimes(3)
})

it('should throw if something errors', async () => {
Expand All @@ -130,12 +130,8 @@ describe('configureSSH', () => {
isTest: TestFlag.HAS_CHANGED_FILES
})

try {
await configureSSH(action)
} catch (error) {
expect(error instanceof Error && error.message).toBe(
'The ssh client configuration encountered an error: Mocked throw ❌'
)
}
await expect(configureSSH(action)).rejects.toThrow(
'The ssh client configuration encountered an error: Mocked throw ❌'
)
})
})