Skip to content

Commit

Permalink
Merge pull request #18 from microlinkhq/next
Browse files Browse the repository at this point in the history
ci: better testing setup
  • Loading branch information
Kikobeats authored Apr 1, 2022
2 parents 81223df + 97d0ff5 commit e68883f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
runs-on: ubuntu-latest
container:
image: kikobeats/docker-browserless-vips:latest
image: kikobeats/docker-vips:latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"debug-logfmt": "~1.0.4",
"node-vibrant": "~3.2.1-alpha.1",
"sharp": "~0.30.0"
"sharp": "~0.30.3"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand All @@ -50,7 +50,7 @@
"conventional-github-releaser": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"hexsorter": "latest",
"hex-color-regex": "latest",
"nano-staged": "latest",
"npm-check-updates": "latest",
"prettier-standard": "latest",
Expand Down Expand Up @@ -83,6 +83,9 @@
"update:check": "ncu -- --error-level 2"
},
"license": "MIT",
"ava": {
"workerThreads": false
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand Down
23 changes: 4 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
'use strict'

const { isEmpty, clone, pull } = require('lodash')

const hexSorter = require('hexsorter')
const hexColorRegex = require('hex-color-regex')
const path = require('path')
const test = require('ava')
const fs = require('fs')

const splashy = require('..')
const FIXTURES_PATH = path.resolve(__dirname, 'fixtures')

const SKIP_EXTENSION_TESTS = ['.ico', '.bmp', '.mng']

const images = fs.readdirSync(FIXTURES_PATH)

const sortColors = colors => {
const input = clone(colors)
const output = []

while (!isEmpty(input)) {
const color = hexSorter.mostBrightColor(input)
pull(input, color)
output.push(color)
}

return output
}
const isHexcolor = hex => hexColorRegex({ strict: true }).test(hex)

images.forEach(image => {
const extension = path.extname(image)
;(SKIP_EXTENSION_TESTS.includes(extension) ? test.skip : test)(extension, async t => {
test(extension, async t => {
const filepath = path.resolve(path.resolve(FIXTURES_PATH, image))
const buffer = fs.readFileSync(filepath)
const colors = await splashy(buffer)
t.true(colors.length > 0)
t.snapshot(sortColors(colors))
t.true(colors.every(isHexcolor))
})
})

0 comments on commit e68883f

Please sign in to comment.