Skip to content

Commit

Permalink
Implement fetching, filtering and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dorny committed May 20, 2020
1 parent d475d5d commit 4e726dd
Show file tree
Hide file tree
Showing 10 changed files with 31,283 additions and 327 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
Expand Down
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}
90 changes: 68 additions & 22 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,73 @@
import {wait} from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import Filter from '../src/filter'

test('throws invalid number', async () => {
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
describe('yaml filter parsing tests', () => {
test('throws if yaml is not a dictionary', () => {
const yaml = 'not a dictionary'
const t = () => new Filter(yaml)
expect(t).toThrow(/^Invalid filter.*/)
})
test('throws on invalid yaml', () => {
const yaml = `
src:
src/**/*.js
`
const t = () => new Filter(yaml)
expect(t).toThrow(/^Invalid filter.*/)
})
test('throws if pattern is not a string', () => {
const yaml = `
src:
- src/**/*.js
- dict:
some: value
`
const t = () => new Filter(yaml)
expect(t).toThrow(/^Invalid filter.*/)
})
})

test('wait 500 ms', async () => {
const start = new Date()
await wait(500)
const end = new Date()
var delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
})
describe('matching tests', () => {
test('matches single rule in single group', () => {
const yaml = `
src:
- src/**/*.js
`
const filter = new Filter(yaml)
const match = filter.match(['src/app/module/file.js'])
expect(match.src).toBeTruthy()
})

test('no match when file is in different folder', () => {
const yaml = `
src:
- src/**/*.js
`
const filter = new Filter(yaml)
const match = filter.match(['not_src/other_file.js'])
expect(match.src).toBeFalsy()
})

test('match only within second groups ', () => {
const yaml = `
src:
- src/**/*.js
test:
- test/**/*.js
`
const filter = new Filter(yaml)
const match = filter.match(['test/test.js'])
expect(match.src).toBeFalsy()
expect(match.test).toBeTruthy()
})

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = '500'
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: process.env
}
console.log(cp.execSync(`node ${ip}`, options).toString())
test('match only withing second rule of single group', () => {
const yaml = `
src:
- src/**/*.js
- test/**/*.js
`
const filter = new Filter(yaml)
const match = filter.match(['test/test.js'])
expect(match.src).toBeTruthy()
})
})
Loading

0 comments on commit 4e726dd

Please sign in to comment.