diff --git a/CHANGELOG.md b/CHANGELOG.md index 5146944e..f9f3cc92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # mochawesome-report-generator changelog ## [Unreleased] +### Added +- Support adding video in context via data uri [mochawesome #372](https://github.com/adamgruber/mochawesome/issues/372) ## [6.1.1] - 2022-03-05 ### Fixed diff --git a/package.json b/package.json index 1470c061..c0c47da6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "lint": "eslint src test --ext js", "stylelint": "stylelint src/**/*.css src/components/**/*.css", "pretest": "npm run lint", - "test": "cross-env NODE_ENV=test nyc mocha \"test/spec/**/*.test.js\"", + "test": "cross-env NODE_ENV=test nyc mocha \"test/spec/**/*.test.js\" --exit", "tdd": "cross-env NODE_ENV=test nyc mocha --watch \"test/spec/**/*.test.js\"", "test:single": "cross-env NODE_ENV=test nyc mocha ", "test:functional": "cross-env NODE_ENV=test node ./test-functional/index.js", diff --git a/src/client/components/test/context.js b/src/client/components/test/context.js index e64567d5..4d14d819 100644 --- a/src/client/components/test/context.js +++ b/src/client/components/test/context.js @@ -7,20 +7,26 @@ import styles from './test.css'; const cx = classNames.bind(styles); -const videoRegEx = /(?:mp4|webm)$/i; +const videoRegEx = /(mp4|webm)$/i; const imgRegEx = /(?:png|jpe?g|gif)$/i; const protocolRegEx = /^(?:(?:https?|ftp):\/\/)/i; const urlRegEx = /^(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/; // eslint-disable-line const base64ImgRegEx = /^data:image\/([a-zA-Z0-9-_.])+;base64,([^"]*)$/i; +const base64VidRegEx = /^data:video\/(mp4|webm);base64,(?:[^"]*)$/i; -const isVideo = str => { +const getVideoType = str => { if (!isString(str)) { - return false; + return undefined; } const hashIndex = str.indexOf('#'); - return videoRegEx.test(hashIndex > 0 ? str.slice(0, hashIndex) : str); -} + + const [, type] = + videoRegEx.exec(hashIndex > 0 ? str.slice(0, hashIndex) : str) || + base64VidRegEx.exec(str) || + []; + return type || undefined; +}; class TestContext extends Component { static displayName = 'TestContext'; @@ -34,22 +40,25 @@ class TestContext extends Component { ]), }; - renderVideo = (ctx, title) => { + renderVideo = (ctx, title, type) => { const isUrl = urlRegEx.test(ctx); const hasProtocol = protocolRegEx.test(ctx); const linkUrl = isUrl && !hasProtocol ? `http://${ctx}` : ctx; return ( -