Skip to content

Commit

Permalink
Fix functional tests (#150)
Browse files Browse the repository at this point in the history
* Remove setup-stack step

* Remove glob
  • Loading branch information
fabasoad authored Oct 9, 2022
1 parent 909e8b8 commit 2890638
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 122 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
install_stack: [true, false]
install_kitten: [true, false]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -27,21 +25,15 @@ jobs:
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Compile
if: ${{ steps.yarn-cache.outputs.cache-hit != 'true' }}
run: yarn install --ignore-scripts
- name: Build
run: yarn run build
- name: Setup Stack
if: ${{ matrix.install_stack }}
uses: mstksg/setup-stack@v2
- name: Setup Kitten
if: ${{ matrix.install_kitten }}
uses: ./
- name: "Setup Kitten (skipped: ${{ matrix.install_kitten }})"
uses: ./
- name: Run script (Linux, MacOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
"@actions/core": "1.10.0",
"@actions/tool-cache": "2.0.1",
"command-exists": "1.2.9",
"glob": "8.0.3",
"winston": "3.8.2"
},
"devDependencies": {
"@types/chai": "4.3.3",
"@types/command-exists": "1.2.0",
"@types/glob": "8.0.0",
"@types/jest": "29.1.2",
"@types/node": "18.8.3",
"@types/sinon": "10.0.13",
Expand Down
7 changes: 3 additions & 4 deletions src/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import CliExeNameProvider from './CliExeNameProvider'
import LoggerFactory from './LoggerFactory'

export default class Cache implements ICache {
private version: string
private provider: ICliExeNameProvider
private log: Logger
private readonly version: string
private readonly provider: ICliExeNameProvider
private readonly log: Logger = LoggerFactory.create(Cache.name)

constructor(
version: string,
cliName: string,
provider: ICliExeNameProvider = new CliExeNameProvider(cliName)) {
this.version = version
this.provider = provider
this.log = LoggerFactory.create('Cache')
}

async cache(execFilePath: string): Promise<void> {
Expand Down
34 changes: 17 additions & 17 deletions src/ExecutableFileFinder.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { sync } from 'glob'
import path from 'path'
import { readdirSync, statSync } from 'fs'
import { Logger } from 'winston'
import CliExeNameProvider from './CliExeNameProvider'
import { KITTEN_CLI_NAME } from './consts'
import LoggerFactory from './LoggerFactory'

export default class ExecutableFileFinder implements IExecutableFileFinder {
private log: Logger
private provider: ICliExeNameProvider
private readonly log: Logger = LoggerFactory.create(ExecutableFileFinder.name)
private readonly provider: ICliExeNameProvider

constructor(
cliName: string,
provider: ICliExeNameProvider = new CliExeNameProvider(cliName)) {
this.provider = provider
this.log = LoggerFactory.create('ExecutableFileFinder')
}

find(folderPath: string, cliName: string): string {
const pattern: string =
`${folderPath}${path.sep}**${path.sep}${cliName}*`
const files: string[] = sync(pattern)
.filter((f: string) => f.endsWith(this.provider.getExeFileName()))
if (files.length === 0) {
throw new Error('Execution file has not been found under ' +
`${folderPath} folder using ${pattern} pattern`)
} else if (files.length > 1) {
throw new Error('There are more than 1 execution file has been found ' +
`under ${folderPath} folder using ${pattern} pattern: ${files}`)
find(dirPath: string): string {
const files: string[] = [dirPath]
while (files.length > 0) {
const filePath: string = files.pop() || ''
if (statSync(filePath).isDirectory()) {
readdirSync(filePath)
.forEach((f: string) => files.push(`${filePath}${path.sep}${f}`))
} else if (filePath.endsWith(this.provider.getExeFileName())) {
this.log.info(`${KITTEN_CLI_NAME} path is ${filePath}`)
return filePath
}
}
this.log.info(`${cliName} path is ${files[0]}`)
return files[0]
throw new Error('Execution file has not been found under ' +
`${dirPath} folder`)
}
}
86 changes: 36 additions & 50 deletions src/__tests__/ExecutableFileFinder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,46 @@
import { sync } from 'glob'
import itParam from 'mocha-param'
import path from 'path'
import ExecutableFileFinder from '../ExecutableFileFinder'
import fs from 'fs';
import itParam from 'mocha-param';

jest.mock('glob', () => ({ sync: jest.fn() }))
const TEST_EXE = 'file.exe'

interface INegativeTestFixture {
message: string
suffix: string
}
jest.mock('fs', () => ({
readdirSync: jest.fn((dirPath: string) => {
switch (dirPath) {
case 'folder1': return ['file.txt', 'folder2']
case 'folder1/folder2': return [TEST_EXE]
default: return []
}
}),
statSync: jest.fn((dirPath: string) => ({
isDirectory: jest.fn(() => dirPath.endsWith('folder1') ||
dirPath.endsWith('folder2'))
}))
}))

describe('ExecutableFileFinder', () => {
const SUFFIX: string = '3ttg37ne'
const items: INegativeTestFixture[] = [{
message: 'There are more than 1 execution file has been found',
suffix: SUFFIX
}, {
message: 'Execution file has not been found',
suffix: 'u4h0t03e'
}]
describe('ExecutableFileFinder::find', () => {
let finder: ExecutableFileFinder

it('should find successfully', () => {
const folderPath: string = '4se2ov6f'
const cliName: string = '1clx8w43'
const files: string[] = [cliName + SUFFIX, cliName];
(sync as jest.Mock).mockImplementation(() => files)
const finder: ExecutableFileFinder = new ExecutableFileFinder(cliName, {
getExeFileName: (): string => SUFFIX
beforeEach(() => {
(fs.readdirSync as jest.Mock).mockClear();
(fs.statSync as jest.Mock).mockClear()
const cliName = '1clx8w43'
finder = new ExecutableFileFinder(cliName, {
getExeFileName: () => TEST_EXE
})
const actual: string = finder.find(folderPath, cliName)
expect((sync as jest.Mock).mock.calls.length).toBe(1)
expect(sync).toHaveBeenCalledWith(
`${folderPath}${path.sep}**${path.sep}${cliName}*`)
expect(actual).toBe(files[0])
})

itParam('should throw error (${value.message})',
items, (item: INegativeTestFixture) => {
const folderPath: string = '4se2ov6f'
const cliName: string = '1clx8w43'
const files: string[] = [cliName + SUFFIX, `gt11c1zr${SUFFIX}`];
(sync as jest.Mock).mockImplementation(() => files)
const finder: ExecutableFileFinder = new ExecutableFileFinder(cliName, {
getExeFileName: (): string => item.suffix
})
try {
finder.find(folderPath, cliName)
} catch (e) {
expect((<Error>e).message).toContain(item.message)
expect((sync as jest.Mock).mock.calls.length).toBe(1)
expect(sync).toHaveBeenCalledWith(
`${folderPath}${path.sep}**${path.sep}${cliName}*`)
return
}
fail()
})
it('should find successfully', () => {
const dirPath = 'folder1'
const actual: string = finder.find(dirPath)
expect(actual).toBe(`folder1/folder2/${TEST_EXE}`)
})

afterEach(() => (sync as jest.Mock).mockClear())
itParam(
'should not find successfully (${value})',
['folder3', null],
(dirPath: string) => {
expect(() => finder.find(dirPath)).toThrow(
`Execution file has not been found under ${dirPath} folder`)
})
})
38 changes: 0 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -730,14 +730,6 @@
resolved "https://registry.yarnpkg.com/@types/command-exists/-/command-exists-1.2.0.tgz#d97e0ed10097090e4ab0367ed425b0312fad86f3"
integrity sha512-ugsxEJfsCuqMLSuCD4PIJkp5Uk2z6TCMRCgYVuhRo5cYQY3+1xXTQkSlPtkpGHuvWMjS2KTeVQXxkXRACMbM6A==

"@types/glob@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.0.0.tgz#321607e9cbaec54f687a0792b2d1d370739455d2"
integrity sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.3":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
Expand Down Expand Up @@ -777,11 +769,6 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==

"@types/minimatch@*":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==

"@types/node@*", "@types/node@18.8.3":
version "18.8.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.8.3.tgz#ce750ab4017effa51aed6a7230651778d54e327c"
Expand Down Expand Up @@ -1065,13 +1052,6 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

braces@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
Expand Down Expand Up @@ -1679,17 +1659,6 @@ glob-parent@^6.0.1:
dependencies:
is-glob "^4.0.3"

glob@8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

glob@^7.1.3, glob@^7.1.4:
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
Expand Down Expand Up @@ -2450,13 +2419,6 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
dependencies:
brace-expansion "^2.0.1"

mocha-param@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/mocha-param/-/mocha-param-2.0.1.tgz#1865e62868b12678a32bd6e3d0e3ea411c39ebdf"
Expand Down

0 comments on commit 2890638

Please sign in to comment.