Skip to content

Commit

Permalink
Adding tasks for MV3 test build (#15133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Jul 13, 2022
1 parent 0c163dd commit aeb0147
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
32 changes: 27 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ workflows:
- prep-build-test:
requires:
- prep-deps
- prep-build-test-mv3:
requires:
- prep-deps
- prep-build-test-flask:
requires:
- prep-deps
Expand Down Expand Up @@ -200,8 +203,8 @@ jobs:
- persist_to_workspace:
root: .
paths:
- node_modules
- build-artifacts
- node_modules
- build-artifacts

validate-lavamoat-config:
executor: node-browsers-medium-plus
Expand Down Expand Up @@ -305,6 +308,26 @@ jobs:
- dist-test-flask
- builds-test-flask

prep-build-test-mv3:
executor: node-browsers-medium-plus
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Build extension in mv3 for testing
command: yarn build:test:mv3
- run:
name: Move test build to 'dist-test' to avoid conflict with production build
command: mv ./dist ./dist-test-mv3
- run:
name: Move test zips to 'builds-test' to avoid conflict with production build
command: mv ./builds ./builds-test-mv3
- persist_to_workspace:
root: .
paths:
- dist-test-mv3
- builds-test-mv3

prep-build-test:
executor: node-browsers-medium-plus
Expand Down Expand Up @@ -419,7 +442,6 @@ jobs:
name: Validate release candidate changelog
command: yarn lint:changelog:rc


test-deps-audit:
executor: node-browsers
steps:
Expand Down Expand Up @@ -648,7 +670,7 @@ jobs:
steps:
- add_ssh_keys:
fingerprints:
- "3d:49:29:f4:b2:e8:ea:af:d1:32:eb:2a:fc:15:85:d8"
- '3d:49:29:f4:b2:e8:ea:af:d1:32:eb:2a:fc:15:85:d8'
- checkout
- attach_workspace:
at: .
Expand All @@ -670,7 +692,7 @@ jobs:
- run:
name: test:coverage:jest
command: yarn test:coverage:jest
- run:
- run:
name: Validate coverage thresholds
command: |
if ! git diff --exit-code jest.config.js development/jest.config.js; then
Expand Down
44 changes: 32 additions & 12 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,20 @@ const postProcessServiceWorker = (
mv3BrowserPlatforms,
fileList,
applyLavaMoat,
testing,
) => {
mv3BrowserPlatforms.forEach((browser) => {
const appInitFile = `./dist/${browser}/app-init.js`;
const fileContent = readFileSync('./app/scripts/app-init.js', 'utf8');
const fileOutput = fileContent
.replace('/** FILE NAMES */', fileList)
.replace(
let fileOutput = fileContent.replace('/** FILE NAMES */', fileList);
if (!testing) {
// Lavamoat is always set to true in testing mode
// This is to enable capturing initialisation time stats using e2e with lavamoat statsMode enabled
fileOutput = fileContent.replace(
'const applyLavaMoat = true;',
`const applyLavaMoat = ${applyLavaMoat};`,
);
}
writeFileSync(appInitFile, fileOutput);
});
};
Expand Down Expand Up @@ -420,16 +424,32 @@ async function bundleMV3AppInitialiser({
shouldLintFenceFiles,
})();

postProcessServiceWorker(mv3BrowserPlatforms, fileList, applyLavaMoat);
postProcessServiceWorker(
mv3BrowserPlatforms,
fileList,
applyLavaMoat,
testing,
);

let prevChromeFileContent;
watch('./dist/chrome/app-init.js', () => {
const chromeFileContent = readFileSync('./dist/chrome/app-init.js', 'utf8');
if (chromeFileContent !== prevChromeFileContent) {
prevChromeFileContent = chromeFileContent;
postProcessServiceWorker(mv3BrowserPlatforms, fileList, applyLavaMoat);
}
});
if (devMode && !testing) {
let prevChromeFileContent;
watch('./dist/chrome/app-init.js', () => {
const chromeFileContent = readFileSync(
'./dist/chrome/app-init.js',
'utf8',
);
if (chromeFileContent !== prevChromeFileContent) {
prevChromeFileContent = chromeFileContent;
postProcessServiceWorker(mv3BrowserPlatforms, fileList, applyLavaMoat);
}
});
}

if (testing) {
const content = readFileSync('./dist/chrome/runtime-lavamoat.js', 'utf8');
const fileOutput = content.replace('statsMode = false', 'statsMode = true');
writeFileSync('./dist/chrome/runtime-lavamoat.js', fileOutput);
}

console.log(`Bundle end: service worker app-init.js`);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js",
"build:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn build test",
"build:test:flask": "yarn build test --build-type flask",
"build:test:mv3": "ENABLE_MV3=true yarn build test",
"test": "yarn lint && yarn test:unit && yarn test:unit:jest",
"dapp": "node development/static-server.js node_modules/@metamask/test-dapp/dist --port 8080",
"dapp-chain": "GANACHE_ARGS='-b 2' concurrently -k -n ganache,dapp -p '[{time}][{name}]' 'yarn ganache:start' 'sleep 5 && yarn dapp'",
Expand Down

0 comments on commit aeb0147

Please sign in to comment.