Skip to content

Commit

Permalink
fix: cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
hikerpig committed Dec 29, 2023
1 parent ea433ad commit 2727750
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/pintora-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"scripts": {
"compile": "tsc",
"watch": "tsc -w",
"test": "jest"
"test": "jest ---forceExit"
},
"bugs": {
"url": "https://github.com/hikerpig/pintora/issues"
Expand Down
12 changes: 11 additions & 1 deletion packages/pintora-cli/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ function renderPrepare(opts: CLIRenderOptions) {
// setup the env for renderer
global.window = dom.window as any
global.document = document

const noop = () => {}
Object.assign(global as any, {
navigator: {},
addEventListener: noop,
removeEventListener: noop,
CanvasPattern,
requestAnimationFrame(cb: () => void) {
cb()
}
})
;(dom.window as any).devicePixelRatio = devicePixelRatio
;(global as any).CanvasPattern = CanvasPattern

return {
container,
Expand Down
5 changes: 5 additions & 0 deletions packages/pintora-renderer/src/renderers/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ export class CanvasRenderer extends BaseRenderer {
getGRenderer() {
return new Renderer()
}

override getRootElement() {
if (!this.gcvs) return
return (this.gcvs.context.contextService as any).$canvas
}
}
5 changes: 5 additions & 0 deletions packages/pintora-renderer/src/renderers/SvgRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export class SvgRenderer extends BaseRenderer {
return new Renderer()
}

override getRootElement() {
if (!this.gcvs) return
return (this.gcvs.context.contextService as any).$namespace
}

onShapeAdd(shape: GElement, mark: Mark) {
super.onShapeAdd(shape, mark)

Expand Down
5 changes: 1 addition & 4 deletions packages/pintora-renderer/src/renderers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ export abstract class BaseRenderer implements IRenderer {
return this
}

getRootElement() {
if (!this.gcvs) return
return this.gcvs.getConfig().el
}
abstract getRootElement(): Element

protected addBgShape() {
if (this.ir.bgColor && this.gcvs) {
Expand Down

0 comments on commit 2727750

Please sign in to comment.