-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from microlinkhq/next
ci: better testing setup
- Loading branch information
Showing
3 changed files
with
10 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) |