This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding utilities for cards local generation & testing (#34)
* feat: getuserdata private * fix: fix incorrect import * feat: refractor & add local scripts * feat: add local dev generation script * last touches * refractor: suggestions * docs: add documentation for local dev script * refractor: change output folder * update local dev user command name
- Loading branch information
1 parent
bb520af
commit c5a5fec
Showing
5 changed files
with
100 additions
and
39 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,36 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { AppModule } from "../../src/app.module"; | ||
import { SocialCardService } from "../../src/social-card/social-card.service"; | ||
import { existsSync } from "node:fs"; | ||
import { mkdir, writeFile } from "fs/promises"; | ||
|
||
|
||
const testUsernames = [ | ||
"bdougie", "deadreyo", "defunkt", "0-vortex", | ||
]; | ||
|
||
const folderPath = "dist"; | ||
|
||
async function testUserCards () { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule] }).compile(); | ||
|
||
const app = moduleFixture.createNestApplication(); | ||
|
||
await app.init(); | ||
|
||
const instance = app.get(SocialCardService); | ||
|
||
const promises = testUsernames.map(async username => { | ||
const { svg } = await instance.generateCardBuffer(username); | ||
|
||
if (!existsSync(folderPath)) { | ||
await mkdir(folderPath); | ||
} | ||
await writeFile(`${folderPath}/${username}.svg`, svg); | ||
}); | ||
|
||
// generating sequential: 10.5 seconds, parallel: 4.5 seconds | ||
await Promise.all(promises); | ||
} | ||
|
||
testUserCards(); |