Skip to content

Commit

Permalink
Merge pull request #1 from tanmayghosh2507/taghos-jest
Browse files Browse the repository at this point in the history
Preparing for first release
  • Loading branch information
tanmayghosh2507 authored Apr 29, 2022
2 parents fbb3af4 + 250fc79 commit 93ee497
Show file tree
Hide file tree
Showing 23 changed files with 1,127 additions and 10,627 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dist/
lib/
node_modules/
1 change: 1 addition & 0 deletions .github/workflows/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tanmayghosh2507 @wlhutchison @safalk
5 changes: 4 additions & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:

- name: Build GitHub Action
run: npm run build


- name: Tests
run: npm run test

# include any workflow/action specific dependencies

- uses: ./ #picks the current action PR code.
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
__tests__/CACHE/*
__tests__/TEMP/*

# Ignore jest.setup.json file
jest.setup.json
/.vs
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest: current file",
//"env": { "NODE_ENV": "test" },
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}", "--config", "jest.config.js"],
"console": "integratedTerminal",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
95 changes: 95 additions & 0 deletions __tests__/Helper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import * as io from '@actions/io'
import * as core from '@actions/core'
import {getEnvVar, getInputWithDefault, getTempFileName, parseBoolean} from '../src/helpers'
const fs = require('fs')

describe('Helper Unit Tests', () => {
beforeEach(async () => {
jest.mock('@actions/core')
jest.spyOn(core, 'debug')
jest.spyOn(core, 'info')
jest.spyOn(core, 'error')
})

it('getTempFileName successful - Generate Temp file', () => {
// Arrange
jest.mock('fs')
jest.spyOn(fs, 'existsSync')
fs.existsSync.mockReturnValueOnce(true).mockReturnValue(false)

// Act
getTempFileName()

// Assert
expect(core.error).not.toHaveBeenCalled()
})

it('getTempFileName successful - Exists even after 5 attempts', () => {
// Arrange
jest.mock('fs')
jest.spyOn(fs, 'existsSync')
fs.existsSync.mockReturnValue(true)

// Act
try {
getTempFileName()
} catch (err) {
expect(err.message).toBe('Unable to create unique temp file name after 6 attempts')
}

// Assert
expect(core.error).toHaveBeenCalled()
})

it('parseBoolean returns true for string true', () => {
var out = parseBoolean('true')

expect(out).toBe(true)
})

it('parseBoolean returns true for int 1', () => {
var out = parseBoolean('1')

expect(out).toBe(true)
})

it('parseBoolean returns false for string false', () => {
var out = parseBoolean('false')

expect(out).toBe(false)
})

it('parseBoolean returns false for int 0', () => {
var out = parseBoolean('0')

expect(out).toBe(false)
})

it('getInputWithDefault returns provided input', () => {
// Arrange
jest.spyOn(core, 'getInput').mockReturnValue('sampleInput')

// Act
var out = getInputWithDefault('input', 'defaultValue')

// Assert
expect(out).toBe('sampleInput')
})

it('getInputWithDefault returns default as no input provided', () => {
// Arrange
jest.spyOn(core, 'getInput').mockReturnValue('')

// Act
var out = getInputWithDefault('input', 'defaultValue')

// Assert
expect(out).toBe('defaultValue')
})

it('getEnvVar success', () => {
var out = getEnvVar('GITHUB_WORKFLOW')

expect(out).toBe('1')
})
})
10 changes: 5 additions & 5 deletions __tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as hlp from '../src/helpers'

test('test getTempPath', async () => {
let tempPath = hlp.getTempPath()
expect(tempPath.length).toBeGreaterThan(0)
let tempPath = hlp.getTempPath()
expect(tempPath.length).toBeGreaterThan(0)
})

test('test getTempFileName', async () => {
let tempFileName = hlp.getTempFileName()
expect(tempFileName.length).toBeGreaterThan(0)
})
let tempFileName = hlp.getTempFileName()
expect(tempFileName.length).toBeGreaterThan(0)
})
7 changes: 3 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as a from '../src/action'
import * as path from 'path'
import * as a from '../src/Action'

test('getSymbolServiceUri', async () => {
await a.run()
})
await a.run()
})
Loading

0 comments on commit 93ee497

Please sign in to comment.