Skip to content

Commit

Permalink
tests for svg trace/posterize
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkurt committed Sep 10, 2018
1 parent 3eb50d8 commit 47385c7
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@
"css-select": "^1.3.0-rc0",
"domutils": "^1.6.2",
"eventemitter2": "^5.0.1",
"file-loader": "^2.0.0",
"htmlparser2": "^3.9.2",
"http-cache-semantics": "^3.8.1",
"image-webpack-loader": "^4.3.1",
"nock": "^9.2.6",
"nyc": "^13.0.0",
"raw-loader": "^0.5.1",
"standard-version": "^4.4.0",
"ts-loader": "^3.2.0",
"ts-node": "^3.3.0",
Expand Down Expand Up @@ -128,4 +130,4 @@
],
"all": true
}
}
}
2 changes: 1 addition & 1 deletion src/cmd/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ root
try {
const app = appStore.app
const rt = new LocalRuntime(
new App({ app: app.name, version: app.version, source: "", source_hash: "", config: {}, secrets: {}, env: "test" }),
new App({ app: app.name, version: app.version, source: "", source_hash: "", config: { files: ["./fixtures/"] }, secrets: {}, env: "test" }),
new Bridge({
dataStore: new SQLiteDataStore(app.name, 'test')
})
Expand Down
18 changes: 16 additions & 2 deletions v8env/src/fly/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,26 @@ export class Image {
return i
}

traceSVG(mode?: string): string {
return bridge.dispatchSync("fly.Image.traceSVG", this._ref, mode)
/**
* Traces an image as an SVG.
* @returns SVG data as a string
*/
trace(): string {
return bridge.dispatchSync("fly.Image.traceSVG", this._ref)
}

/**
* Trace an image multiple times and return the combined SVG data as a string.
* This function is useful for turning photographs into monochrome SVGs.
* @returns SVG data as a string
*/
posterize() {
return bridge.dispatchSync("fly.Image.traceSVG", this._ref, "posterize")
}
}

export namespace Image {

export interface Color {
/** red channel, 0-255 */
r: number,
Expand Down
6 changes: 6 additions & 0 deletions v8env/test/fixtures/picture.posterize.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions v8env/test/fixtures/picture.trace.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions v8env/test/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { expect } from 'chai'
const logo = require("./fixtures/logo.png")
const picture = require("./fixtures/picture.jpg")
const overlay = require("./fixtures/overlay.png")
const svgTrace = require("./fixtures/picture.trace")
const svgPosterize = require("./fixtures/picture.posterize")
const { Image } = require("@fly/image")
describe("Image", () => {
it("Image(create)", () => {
Expand Down Expand Up @@ -94,4 +96,17 @@ describe("Image", () => {
expect(err).to.not.be.null
expect(err.toString()).to.include("unsupported image format")
})//*/

it("trace()", async () => {
const img = new Image(picture)
const svg = img.trace()

expect(svg).to.eq(svgTrace, "SVG data didn't match")
})
it("posterize", async () => {
const img = new Image(picture)
const svg = img.posterize()

expect(svg).to.eq(svgPosterize, "SVG data didn't match")
})
})
Loading

0 comments on commit 47385c7

Please sign in to comment.