-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for loadFont, fixes #147
- Loading branch information
Showing
5 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {assert} from 'chai'; | ||
import testRender from './test-render'; | ||
import testRendering from './test-rendering'; | ||
|
||
const p5 = window.p5; | ||
|
||
export {assert, p5, testRender}; | ||
export {assert, p5, testRender, testRendering}; |
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,30 @@ | ||
import testRender from './test-render'; | ||
import {p5svg, p5canvas} from './test-render'; | ||
|
||
export default async function testRendering(options = { | ||
draw: (p) => {}, | ||
before: async (p) => {} | ||
}) { | ||
// Waiting for p5svg & p5canvas setup done | ||
while (true) { | ||
if (p5svg.__ready && p5canvas.__ready) { | ||
break; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
// Before | ||
if (options.before) { | ||
await options.before(p5svg); | ||
await options.before(p5canvas); | ||
} | ||
// Draw | ||
return new Promise((resolve, reject) => { | ||
testRender(options.draw, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} |
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,26 @@ | ||
import {p5, testRendering} from '../../lib'; | ||
|
||
describe('Typography', function() { | ||
this.timeout(0); | ||
|
||
// https://p5js.org/reference/#/p5/loadFont | ||
describe('loadFont', function() { | ||
it('should load font', async function() { | ||
let myFont; | ||
return testRendering({ | ||
before: async function(p) { | ||
myFont = await new Promise((resolve, reject) => { | ||
p.loadFont('https://unpkg.com/[email protected]/fonts/FontAwesome.otf', resolve, reject); | ||
}) | ||
}, | ||
draw: function(p) { | ||
p.fill('#ED225D'); | ||
p.textFont(myFont); | ||
p.textSize(36); | ||
p.text("\uf092", 10, 50); | ||
} | ||
}) | ||
}); | ||
}); | ||
|
||
}); |