-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] tools: update debug script, add tests
- Loading branch information
Showing
8 changed files
with
157 additions
and
40 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* We can only make one test per file, since the debug tool modify in place | ||
* the owl object in a way that is difficult to undo. | ||
*/ | ||
|
||
import { debugOwl } from "../../tools/debug"; | ||
import * as owl from "../../src/index"; | ||
|
||
import { Component, Env } from "../../src/component/component"; | ||
import { xml } from "../../src/tags"; | ||
import { useState } from "../../src/hooks"; | ||
import { makeTestFixture, makeTestEnv, nextTick } from "../helpers"; | ||
|
||
let fixture: HTMLElement = makeTestFixture(); | ||
let env: Env = makeTestEnv(); | ||
Component.env = env; | ||
|
||
debugOwl(owl, {}); | ||
|
||
test("can log full lifecycle", async () => { | ||
const steps: string[] = []; | ||
const log = console.log; | ||
console.log = arg => steps.push(arg); | ||
|
||
class Child extends Component<any, any> { | ||
static template = xml`<div>child</div>`; | ||
} | ||
|
||
class Parent extends Component<any, any> { | ||
static template = xml`<div><Child t-if="state.flag"/></div>`; | ||
static components = { Child }; | ||
state = useState({ flag: false }); | ||
} | ||
|
||
const parent = new Parent(null, {}); | ||
await parent.mount(fixture); | ||
|
||
parent.state.flag = true; | ||
await nextTick(); | ||
|
||
expect(steps).toEqual([ | ||
"[OWL_DEBUG] Parent<id=1> constructor, props={}", | ||
"[OWL_DEBUG] Parent<id=1> mount", | ||
"[OWL_DEBUG] Parent<id=1> willStart", | ||
"[OWL_DEBUG] Parent<id=1> rendering template", | ||
"[OWL_DEBUG] Parent<id=1> mounted", | ||
"[OWL_DEBUG] Parent<id=1> render", | ||
"[OWL_DEBUG] Parent<id=1> rendering template", | ||
"[OWL_DEBUG] Child<id=2> constructor, props={}", | ||
"[OWL_DEBUG] Child<id=2> willStart", | ||
"[OWL_DEBUG] Child<id=2> rendering template", | ||
"[OWL_DEBUG] Parent<id=1> willPatch", | ||
"[OWL_DEBUG] Child<id=2> mounted", | ||
"[OWL_DEBUG] Parent<id=1> patched" | ||
]); | ||
console.log = log; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* We can only make one test per file, since the debug tool modify in place | ||
* the owl object in a way that is difficult to undo. | ||
*/ | ||
|
||
import { debugOwl } from "../../tools/debug"; | ||
import * as owl from "../../src/index"; | ||
|
||
import { Component, Env } from "../../src/component/component"; | ||
import { xml } from "../../src/tags"; | ||
import { makeTestFixture, makeTestEnv } from "../helpers"; | ||
|
||
let fixture: HTMLElement = makeTestFixture(); | ||
let env: Env = makeTestEnv(); | ||
Component.env = env; | ||
|
||
debugOwl(owl, { logScheduler: true }); | ||
|
||
test("can log scheduler start and stop", async () => { | ||
const steps: string[] = []; | ||
const log = console.log; | ||
console.log = arg => steps.push(arg); | ||
|
||
class Child extends Component<any, any> { | ||
static template = xml`<div>child</div>`; | ||
} | ||
|
||
class Parent extends Component<any, any> { | ||
static template = xml`<div><Child /></div>`; | ||
static components = { Child }; | ||
} | ||
|
||
const parent = new Parent(null, {}); | ||
await parent.mount(fixture); | ||
|
||
expect(steps).toEqual([ | ||
"[OWL_DEBUG] Parent<id=1> constructor, props={}", | ||
"[OWL_DEBUG] Parent<id=1> mount", | ||
"[OWL_DEBUG] Parent<id=1> willStart", | ||
"[OWL_DEBUG] scheduler: start running tasks queue", | ||
"[OWL_DEBUG] Parent<id=1> rendering template", | ||
"[OWL_DEBUG] Child<id=2> constructor, props={}", | ||
"[OWL_DEBUG] Child<id=2> willStart", | ||
"[OWL_DEBUG] Child<id=2> rendering template", | ||
"[OWL_DEBUG] Child<id=2> mounted", | ||
"[OWL_DEBUG] Parent<id=1> mounted", | ||
"[OWL_DEBUG] scheduler: stop running tasks queue" | ||
]); | ||
console.log = log; | ||
}); |
File renamed without changes.
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