Skip to content

Commit b911496

Browse files
Refactor sanity report generation
1 parent b447fea commit b911496

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test": "npm run test:api && npm run test:unit",
3333
"test:sanity-test": "BABEL_ENV=test nyc --reporter=html mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill --reporter-options reportDir=mochawesome-report,reportFilename=mochawesome.json",
3434
"test:sanity": "npm run test:sanity-test || true",
35-
"test:sanity-report": "marge mochawesome-report/mochawesome.json -f sanity-report.html --inline && node sanity-report.mjs",
35+
"test:sanity-report": "node sanity-report.mjs",
3636
"test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill",
3737
"test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill",
3838
"test:typescript": "jest --testPathPattern=test/typescript --config ./jest.config.js --coverage",

sanity-report.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ import Slack from '@slack/bolt'
22
const { App } = Slack
33
import dotenv from 'dotenv'
44
import fs from 'fs'
5+
import { execSync } from 'child_process'
6+
import path from 'path'
57

68
dotenv.config()
79

10+
// Marge expects meta.marge.options to be an Object; mochawesome leaves it null. Patch before marge.
11+
const reportJsonPath = path.join(process.cwd(), 'mochawesome-report', 'mochawesome.json')
12+
const json = JSON.parse(fs.readFileSync(reportJsonPath, 'utf8'))
13+
if (json.meta?.marge?.options == null) {
14+
json.meta.marge.options = {}
15+
fs.writeFileSync(reportJsonPath, JSON.stringify(json))
16+
}
17+
execSync('marge mochawesome-report/mochawesome.json -f sanity-report.html --inline', { stdio: 'inherit', cwd: process.cwd() })
18+
819
const mochawesomeJsonOutput = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf8')
920
const mochawesomeReport = JSON.parse(mochawesomeJsonOutput)
1021
const report = `./mochawesome-report/sanity-report.html`
@@ -58,7 +69,6 @@ async function publishMessage (text, report) {
5869
token: process.env.SLACK_BOT_TOKEN,
5970
channel_id: process.env.SLACK_CHANNEL_ID,
6071
initial_comment: '*Here is the report generated*',
61-
filetype: 'html',
6272
filename: 'sanity-report.html',
6373
file: fs.createReadStream(report)
6474
})

0 commit comments

Comments
 (0)