-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup html report generator * Initial phase of the report (hardcoded content) * Remove parcel and simplify report generation * Display screenshots dynamically * Improve the report's responsiveness, look & feel * Clean Up * Clean Up * Correct path to html report & fix tests * Write tests for report generation * Mock progress.cwd * Clean Up * Mock fs.mkdir to prevent creating directories during tests * Prevent test case from creating actual directories
- Loading branch information
Showing
16 changed files
with
530 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
diff/ | ||
latest/ | ||
report/ |
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
"packageName": "com.owldemo", | ||
"quiet": true | ||
}, | ||
"debug": true | ||
"debug": true, | ||
"report": true | ||
} |
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
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,54 @@ | ||
import process from 'process'; | ||
import handlebars from 'handlebars'; | ||
import { promises as fs } from 'fs'; | ||
|
||
import { Logger } from './logger'; | ||
import { generateReport } from './report'; | ||
|
||
describe('report.ts', () => { | ||
const logger = new Logger(); | ||
|
||
const htmlTemplate = '<h1>Hello World<h1>'; | ||
|
||
const readdirMock = jest.spyOn(fs, 'readdir'); | ||
const mkdirMock = jest.spyOn(fs, 'mkdir'); | ||
|
||
const readFileMock = jest.spyOn(fs, 'readFile'); | ||
const writeFileMock = jest.spyOn(fs, 'writeFile'); | ||
|
||
const handlebarsCompileMock = jest | ||
.spyOn(handlebars, 'compile') | ||
.mockImplementationOnce(() => () => '<h1>Hello World Compiled</h1>'); | ||
|
||
const cwdMock = jest | ||
.spyOn(process, 'cwd') | ||
.mockReturnValue('/Users/johndoe/Projects/my-project'); | ||
|
||
beforeAll(() => { | ||
readdirMock.mockReset(); | ||
mkdirMock.mockReset(); | ||
|
||
readFileMock.mockReset(); | ||
writeFileMock.mockReset(); | ||
}); | ||
|
||
afterAll(() => { | ||
cwdMock.mockRestore(); | ||
}); | ||
|
||
it('should get the screenshots and create the html report', async () => { | ||
readFileMock.mockResolvedValueOnce(htmlTemplate); | ||
mkdirMock.mockResolvedValueOnce(undefined); | ||
|
||
await generateReport(logger, 'ios'); | ||
|
||
expect(readdirMock).toHaveBeenCalledWith( | ||
'/Users/johndoe/Projects/my-project/.owl/latest/ios' | ||
); | ||
expect(handlebarsCompileMock).toHaveBeenCalledTimes(1); | ||
expect(writeFileMock).toHaveBeenCalledWith( | ||
'/Users/johndoe/Projects/my-project/.owl/report/index.html', | ||
'<h1>Hello World Compiled</h1>' | ||
); | ||
}); | ||
}); |
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,32 @@ | ||
import path from 'path'; | ||
import handlebars from 'handlebars'; | ||
import { promises as fs } from 'fs'; | ||
|
||
import { Logger } from './logger'; | ||
import { Platform } from './types'; | ||
|
||
export const generateReport = async (logger: Logger, platform: Platform) => { | ||
const cwd = process.cwd(); | ||
const reportDirPath = path.join(cwd, '.owl', 'report'); | ||
const screenshotsDirPath = path.join(cwd, '.owl', 'latest', platform); | ||
const screenshots = await fs.readdir(screenshotsDirPath); | ||
|
||
logger.info(`[OWL] Generating Report`); | ||
|
||
const reportFilename = 'index.html'; | ||
const entryFile = path.join(__dirname, 'report', reportFilename); | ||
const htmlTemplate = await fs.readFile(entryFile, 'utf-8'); | ||
const templateScript = handlebars.compile(htmlTemplate); | ||
const htmlContent = templateScript({ | ||
currentYear: new Date().getFullYear(), | ||
currentDateTime: new Date().toISOString(), | ||
platform, | ||
screenshots, | ||
}); | ||
|
||
await fs.mkdir(reportDirPath, { recursive: true }); | ||
const reportFilePath = path.join(reportDirPath, 'index.html'); | ||
await fs.writeFile(reportFilePath, htmlContent); | ||
|
||
logger.info(`[OWL] Report was built at ${reportDirPath}/${reportFilename}`); | ||
}; |
Oops, something went wrong.