Skip to content

Commit

Permalink
tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
cancerberoSgx committed Nov 11, 2018
1 parent 15cd61d commit 07c5bde
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 2,209 deletions.
2,152 changes: 127 additions & 2,025 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 3 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@
"test-browser-server": "npm run test-browser-build && gulp --gulpfile spec/gulpfile.js jasmine-server",
"test-browser-build": "rm -rf dist && npm run build-ts && cp -r spec/assets dist && npm run bundle",
"bundle": "browserify -d dist/spec/index.js -o dist/bundle.js",
"watch": "npm-watch",
"browser-sync": "browser-sync start --proxy http://localhost:8888 --files dist/bundle.js"
},
"watch": {
"build-ts": {
"patterns": [
"src",
"spec"
],
"extensions": "ts"
},
"bundle": {
"patterns": [
"./dist/src",
"./dist/spec"
],
"extensions": "js"
}
"lint": "tslint \"src/**/*.ts\" \"spec/**/*.ts\"",
"lint-and-fix": "tslint \"src/**/*.ts\" \"spec/**/*.ts\" --fix"
},
"repository": {
"type": "git",
Expand All @@ -55,14 +39,13 @@
"devDependencies": {
"@types/jasmine": "^2.8.11",
"@types/node": "^10.12.3",
"browser-sync": "^2.26.3",
"browserify": "^16.2.3",
"gulp": "^3.9.1",
"gulp-jasmine-browser": "^4.0.2",
"gulp-watch": "^5.0.1",
"jasmine": "^3.3.0",
"npm-watch": "^0.4.0",
"puppeteer": "^1.3.0",
"tslint": "^5.11.0",
"typescript": "^3.1.6"
},
"dependencies": {
Expand Down
12 changes: 6 additions & 6 deletions spec/callSpec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { blobToString, buildInputFile, Call, extractInfo } from '../src';
import { blobToString, buildInputFile, Call, extractInfo } from '../src'

describe('call', () => {

it('should print image metadata as json if output file is .json', async done => {
let processedFiles = await Call([await buildInputFile('fn.png', 'srcFile.png')], ["convert", "srcFile.png", "info.json"])
const processedFiles = await Call([await buildInputFile('fn.png', 'srcFile.png')], ['convert', 'srcFile.png', 'info.json'])
expect(processedFiles[0].name).toBe('info.json')
const data = JSON.parse(await blobToString(processedFiles[0].blob))
expect(data[0].image.baseName).toBe('srcFile.png')
Expand All @@ -14,19 +14,19 @@ describe('call', () => {
const img = await buildInputFile('fn.png')
let info = await extractInfo(img)
expect(info[0].image.geometry.height).toBe(145)
let processedFiles = await Call(
const processedFiles = await Call(
[img],
["convert", "fn.png", "-rotate", "90", "-resize", "200%", 'output.png']
['convert', 'fn.png', '-rotate', '90', '-resize', '200%', 'output.png']
)
expect(processedFiles[0].name).toBe('output.png')
info = await extractInfo(processedFiles[0])
expect(info[0].image.geometry.height).toBe(218)
done()
})

xit('Call rotate and resize should output an image that is equals to the real output', async done => {
xit('Call rotate and resize should output an image that is equals to the real output in the desktop', async done => {
done()
})

//TODO: test that all formats work as input and output
// TODO: test that all formats work as input and output
})
12 changes: 6 additions & 6 deletions spec/executeSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildInputFile, compare, extractInfo } from '../src';
import { execute, executeOne } from '../src';
import { buildInputFile, compare, extractInfo } from '../src'
import { execute, executeOne } from '../src'

describe('execute', () => {

Expand All @@ -26,7 +26,7 @@ describe('execute', () => {
const img1 = await buildInputFile('holocaust.jpg')
const {outputFiles} = await executeOne({inputFiles: [img1], commands: ['convert holocaust.jpg -resize 444x76! output.gif']})
expect(outputFiles[0].name).toBe('output.gif')
let info = await extractInfo(outputFiles[0])
const info = await extractInfo(outputFiles[0])
expect(info[0].image.formatDescription.toLowerCase()).toBe('gif')
expect(info[0].image.geometry.width).toBe(444)
expect(info[0].image.geometry.height).toBe(76)
Expand All @@ -41,7 +41,7 @@ describe('execute', () => {
commands: [
['convert', 'image1.png', '-rotate', '70', 'image2.gif'],
// heads up: next command uses 'image2.gif' which was the output of previous command:
['convert', 'image2.gif', '-scale', '23%', 'image3.jpg'],
['convert', 'image2.gif', '-scale', '23%', 'image3.jpg']
]
})
const result2 = await executeOne({
Expand All @@ -58,7 +58,7 @@ describe('execute', () => {
commands: [
'convert image1.png -rotate 70 image2.gif',
// heads up: next command uses 'image2.gif' which was the output of previous command:
'convert image2.gif -scale 23% image3.jpg',
'convert image2.gif -scale 23% image3.jpg'
]
})
const result2 = await executeOne({
Expand All @@ -70,5 +70,5 @@ describe('execute', () => {
})
})

xit('event emitter', ()=>{})
xit('event emitter', () => {})
})
10 changes: 5 additions & 5 deletions spec/formatSpec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pmap from 'p-map';
import { buildInputFile, compare } from '../src';
import pmap from 'p-map'
import { buildInputFile, compare } from '../src'

describe('formats', () => {

Expand All @@ -9,15 +9,15 @@ describe('formats', () => {

const compares = []
formats.forEach(f1 => {
formats.filter(f2 => f2 != f1).forEach(async f2 => {
formats.filter(f2 => f2 !== f1).forEach(async f2 => {
compares.push([`to_rotate.${f1}`, `to_rotate.${f2}`])
})
})
const results = await pmap(compares, async c => {
return compare(await buildInputFile(c[0]), await buildInputFile(c[1]))
})

expect(results.length).toBeGreaterThan(formats.length*2)
expect(results.length).toBeGreaterThan(formats.length * 2)

results.forEach((r, i) => {
expect(r).toBe(true, `compare(${compares[i][0]}, ${compares[i][1]})`)
Expand All @@ -27,7 +27,7 @@ describe('formats', () => {

})

xit('extractInfo should get correct format and size', ()=>{
xit('extractInfo should get correct format and size', () => {

})
})
2 changes: 1 addition & 1 deletion spec/imageHomeSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildInputFile, createImageHome } from '../src';
import { buildInputFile, createImageHome } from '../src'

describe('imageHome', () => {
it('should allow me to register an image', async done => {
Expand Down
18 changes: 9 additions & 9 deletions spec/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000

require('./callSpec')
require('./executeSpec')
require('./formatSpec')
require('./imageHomeSpec')
require('./testAssetsSpec')
require('./util/cliSpec')
require('./util/htmlSpec')
require('./util/fileSpec')
require('./util/imageSpec')
import * as callSpec from './callSpec'
import * as executeSpec from './executeSpec'
import * as formatSpec from './formatSpec'
import * as imageHomeSpec from './imageHomeSpec'
import * as testAssetsSpec from './testAssetsSpec'
import * as cliSpec from './util/cliSpec'
import * as htmlSpec from './util/htmlSpec'
import * as fileSpec from './util/fileSpec'
import * as imageSpec from './util/imageSpec'
6 changes: 4 additions & 2 deletions spec/testAssetsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ describe('assets', () => {
expect(r.ok).toBe(true)

r = await fetch('fn.png')
expect(r.ok).toBe(true)
expect(r.ok).toBe(true)

r = await fetch('nonexistent.png')
expect(r.ok).toBe(false)

done()
})
})

export default ''
24 changes: 11 additions & 13 deletions spec/util/cliSpec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import { arrayToCli, cliToArray } from '../../src';
import { arrayToCli, cliToArray } from '../../src'

describe('util/cli', () => {

describe('arrayToCli', ()=>{
describe('arrayToCli', () => {
it('should support simple commands', () => {
expect(arrayToCli(['convert', 'foo.png', '-sharpen', '10x8', 'bar.gif']))
.toBe('convert foo.png -sharpen 10x8 bar.gif')

})
it('should escape parenthesis', () => {
expect(arrayToCli(["convert", "foo.png", "(", "+clone", "-channel", "R", "-fx", "B", ")", "+swap", "-channel", "B", "-fx", "v.R", "bar.gif"]))
it('should escape parenthesis', () => {
expect(arrayToCli(['convert', 'foo.png', '(', '+clone', '-channel', 'R', '-fx', 'B', ')', '+swap', '-channel', 'B', '-fx', 'v.R', 'bar.gif']))
.toBe(`convert foo.png \\( +clone -channel R -fx B \\) +swap -channel B -fx v.R bar.gif`)
})
it('should quote arguments with spaces', () => {
expect(arrayToCli(["convert", "input foo.png", "(", "+clone", "-channel", "R", "-fx", "B", ")", "+swap", "-channel", "B", "-fx", "v.R", "output bar.gif"]))
it('should quote arguments with spaces', () => {
expect(arrayToCli(['convert', 'input foo.png', '(', '+clone', '-channel', 'R', '-fx', 'B', ')', '+swap', '-channel', 'B', '-fx', 'v.R', 'output bar.gif']))
.toBe(`convert 'input foo.png' \\( +clone -channel R -fx B \\) +swap -channel B -fx v.R 'output bar.gif'`)
})
})


describe('cliToArray', ()=>{
describe('cliToArray', () => {

it('should support simple commands', () => {
expect(cliToArray(`convert foo.png -rotate 90 bar.gif`))
.toEqual(["convert", "foo.png", "-rotate", "90", "bar.gif"])
.toEqual(['convert', 'foo.png', '-rotate', '90', 'bar.gif'])
})

it('should support commands with quoted arguments', () => {
expect(cliToArray(`convert 'my picture.png' -rotate 90 'output image.png'`))
.toEqual(["convert", "my picture.png", "-rotate", "90", "output image.png"])
.toEqual(['convert', 'my picture.png', '-rotate', '90', 'output image.png'])
})

it('should support escaped parenthesis', () => {
expect(cliToArray(`convert foo.png \\( +clone -channel R -fx B \\) +swap -channel B -fx v.R bar.gif`))
.toEqual(["convert", "foo.png", "(", "+clone", "-channel", "R", "-fx", "B", ")", "+swap", "-channel", "B", "-fx", "v.R", "bar.gif"])
.toEqual(['convert', 'foo.png', '(', '+clone', '-channel', 'R', '-fx', 'B', ')', '+swap', '-channel', 'B', '-fx', 'v.R', 'bar.gif'])
})
})


})
})
34 changes: 15 additions & 19 deletions spec/util/fileSpec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { blobToString, buildInputFile, Call, compare, extractInfo, getFileNameExtension, inputFileToOutputFile, outputFileToInputFile, getFileName } from '../../src';
import { blobToString, buildInputFile, Call, compare, extractInfo, getFileNameExtension, inputFileToOutputFile, outputFileToInputFile, getFileName } from '../../src'

describe('util/file', () => {

describe('buildInputFile', () => {
async function test(urlToFnPng){
async function test(urlToFnPng) {
const file = await buildInputFile(urlToFnPng)
let processedFiles = await Call(
const processedFiles = await Call(
[file],
["convert", "fn.png", "info.json"]
['convert', 'fn.png', 'info.json']
)
expect(processedFiles[0].name).toBe('info.json')
let info = JSON.parse(await blobToString(processedFiles[0].blob))
expect(info[0].image.baseName).toBe('fn.png')
expect(info[0].image.geometry.width).toBe(109)
let processedFiles2 = await Call([file], ["convert", "fn.png", '-scale', '77x99!', "scaled.png"]);
const processedFiles2 = await Call([file], ['convert', 'fn.png', '-scale', '77x99!', 'scaled.png'])
info = await extractInfo(processedFiles2[0])
expect(info[0].image.geometry.width).toBe(77)

Expand All @@ -33,12 +33,10 @@ describe('util/file', () => {
done()
})

xit('should support data:// urls with embedded image content', ()=>{})
xit('should support data:// urls with embedded image content', () => {})
})



describe('outputFileToInputFile and inputFileToOutputFile', ()=>{
describe('outputFileToInputFile and inputFileToOutputFile', () => {

it('outputFileToInputFile should help to use output images in next commands as input images', async done => {
const img = await buildInputFile('holocaust.jpg')
Expand All @@ -50,7 +48,7 @@ describe('util/file', () => {
expect(info2[0].image.geometry.width).toBe(32)
done()
})

it('outputFileToInputFile and inputFileToOutputFile should generate equal images', async done => {
const img = await buildInputFile('holocaust.jpg')
const img2 = await outputFileToInputFile(await inputFileToOutputFile(img), 'img2.jpg')
Expand All @@ -59,10 +57,9 @@ describe('util/file', () => {
})
})

describe('getFileNameExtension', () => {

describe('getFileNameExtension', ()=>{

function test(url, expected){
function test(url, expected) {
expect(getFileNameExtension(url)).toBe(expected)
}

Expand All @@ -79,16 +76,16 @@ describe('util/file', () => {
test('bar.txt?foo=1&t=asdasd', 'txt')
test('/bar.txt?foo=1&t=asdasd', 'txt')
done()
})
})

})

describe('getFileName', ()=>{
describe('getFileName', () => {

function test(url, expected){
function test(url, expected) {
expect(getFileName(url)).toBe(expected)
}

it('should work with absolute urls with query params', async done => {
test('http://foo.co/bar.txt', 'bar.txt')
test('http://foo.co/', '')
Expand All @@ -103,7 +100,6 @@ describe('util/file', () => {
test('bar.txt?foo=1&t=asdasd', 'bar.txt')
test('/bar.txt?foo=1&t=asdasd', 'bar.txt')
done()
})
})
})
})

8 changes: 4 additions & 4 deletions spec/util/htmlSpec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { buildInputFile, loadImageElement, compare, execute } from '../../src';
import { buildInputFile, loadImageElement, compare, execute } from '../../src'

describe('util/html', () => {

describe('loadImageElement', ()=>{
describe('loadImageElement', () => {

it('should display an input image in an html img element', async done => {
const img1 = await buildInputFile('fn.png')
Expand Down Expand Up @@ -37,5 +37,5 @@ describe('util/html', () => {
done()
})
})
})

})
4 changes: 2 additions & 2 deletions spec/util/imageSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildInputFile, compare, extractInfo, MagickInputFile, getFileNameExtension, Call, outputFileToInputFile } from '../../src';
import { buildInputFile, compare, extractInfo, MagickInputFile, getFileNameExtension, Call, outputFileToInputFile } from '../../src'

describe('util/image', () => {

Expand Down Expand Up @@ -33,7 +33,7 @@ describe('util/image', () => {
it('extractInfo should work', async done => {
const img = await buildInputFile('fn.png', 'srcFile.png')
const info = await extractInfo(img)

expect(info[0].image.baseName).toBe('srcFile.png')
expect(info[0].image.geometry.height).toBe(145)
done()
Expand Down
Loading

0 comments on commit 07c5bde

Please sign in to comment.