Skip to content

Commit

Permalink
Add AVA test runner integration
Browse files Browse the repository at this point in the history
Add some test refactoring

Revert jest.environment.js change

Fix ts-comment in test

Add coverage merge process

Fix build issues

Fix test snapshot errors

Fix broken test in snaps-utils

Fix problematic test snapshot

Fix dependencies after rebase

Try to fix problematic snapshots in rollback

Update test snapshot for webpack plugin (root test run)

Try to fix test snapshot on another platform (Ubuntu)

Fix snapshot
  • Loading branch information
david0xd committed Dec 7, 2022
1 parent 7f5cfd4 commit 0e1f3a7
Show file tree
Hide file tree
Showing 21 changed files with 1,118 additions and 192 deletions.
2 changes: 1 addition & 1 deletion packages/examples/examples/bls-signer/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "ixIA4a4Yuk4obx/C6ZwX8wKeYh9pFZTNueB60O7l+rg=",
"shasum": "qjjWC6kWkmjne8yYUCbzXT8M2A51dQkOkZLReVwJM50=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "KmjRmbTSQE1JUeckfcordstsQ9eFtmYWQlPZ7Cw33oI=",
"shasum": "c8hLUTgqFJnm0GgK1XcEW1RbqBxukctXTYqe2av7khk=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "qcHDNajXeVlbmh2ryeq6QezaEBKqbu4MTk6mOXY5oYw=",
"shasum": "xJvyXoMo3QScvGN2840jI4dCfbCFAl1U+1CwmzTu7fs=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/insights/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "bqLsqn8XR9q+XCsxp3NEQ6dzIm57HE0ASyOJiwumjl4=",
"shasum": "a6DXy5lnzdhX/f1YSb0pRFgY8JC2kqbAqd6Rf4iA55g=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/ipfs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "ZcetnugqubraghMtlmyOiPDlUut7RiwTLmQbUwUypls=",
"shasum": "MB9LwXXVRf6E6pm/NYWujpUHAwlTy6GprTfimfG4W5g=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-template.git"
},
"source": {
"shasum": "4aAg0VXdfByp6BWb6DuQo5Ui8rq+dx03/zuVgxp+KG4=",
"shasum": "a6ysW6olvSnmIioMbW8MuMdaLJs+juyktZkiGk+taD4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/rollup/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "wKtIq3NPeNfGAc+yGnrwJPd+C7t0Ty4NzuzVt9r5MSg=",
"shasum": "lEEbARveov0m6UMfgxjN4rOmWaD9v8YyyDKEB+aKRp0=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/typescript/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-template.git"
},
"source": {
"shasum": "VIKG9OZAveGZ+ToGR8v7UoJatUsQJ09BkAgTONdeka0=",
"shasum": "VFv69IsnVj2/exDvHpIDgrVN9pK6rUxpUuFS0M7rjLw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/wasm/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "v/lRHVNTJ+lK+83EWqeQJ7XyE5lQkB49kZxzrIpDZVo=",
"shasum": "EVCVhq+Q9pKC16tiljFmaWj17iRZExrS9YRAsIKOkgk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/webpack/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "LSPylBpL9fDMQaNfdSVf36tUOfEGMVQpldNOnKS3wmI=",
"shasum": "rtiazAiV0nGiwCrfSBLfrq5GQy4z5PrQbOFp2HhFVAU=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports[`plugin applies a transform 1`] = `
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
Expand All @@ -21,15 +20,11 @@ exports[`plugin applies a transform 1`] = `
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
})()({
1: [function (require, module, exports) {
Expand All @@ -50,7 +45,6 @@ exports[`plugin forwards the options 1`] = `
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
Expand All @@ -59,20 +53,15 @@ exports[`plugin forwards the options 1`] = `
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
})()({
1: [function (require, module, exports) {
// foo bar
/* baz qux */
const foo = 'bar';
}, {}]
Expand All @@ -91,7 +80,6 @@ exports[`plugin generates a source map 1`] = `
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
Expand All @@ -100,15 +88,11 @@ exports[`plugin generates a source map 1`] = `
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
})()({
1: [function (require, module, exports) {
Expand All @@ -124,7 +108,7 @@ exports[`plugin generates a source map 1`] = `
};
}, {}]
}, {}, [1]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBQUE7RUFBQTtJQUFBO01BQUE7UUFBQTtVQUFBO1VBQUE7VUFBQTtVQUFBO1VBQUE7UUFBQTs7UUFBQTtVQUFBQTtRQUFBO1FBQUFDO1VBQUE7VUFBQTtRQUFBO01BQUE7O01BQUE7SUFBQTs7SUFBQTs7SUFBQTtFQUFBOztFQUFBO0FBQUE7RUFBQTtJQ0NBQztNQUFBQztJQUFBO01BQ0FDO01BRUE7UUFBQUM7UUFBQUM7TUFBQTtNQUNBO0lBQ0EsQ0FMQTtHRERBO0FBQUEiLCJuYW1lcyI6WyJleHBvcnRzIiwiZSIsIm1vZHVsZSIsInJlcXVlc3QiLCJjb25zb2xlIiwibWV0aG9kIiwiaWQiXSwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vbm9kZV9tb2R1bGVzL2Jyb3dzZXItcGFjay9fcHJlbHVkZS5qcyIsIl9zdHJlYW1fMC5qcyJdLCJzb3VyY2VzQ29udGVudCI6W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CB3b3JsZCFcIik7XG5cbiAgICBjb25zdCB7IG1ldGhvZCwgaWQgfSA9IHJlcXVlc3Q7XG4gICAgcmV0dXJuIG1ldGhvZCArIGlkO1xuICB9O1xuIl19"
`;

exports[`plugin processes files using Browserify 1`] = `
Expand All @@ -139,7 +123,6 @@ exports[`plugin processes files using Browserify 1`] = `
var a = new Error("Cannot find module '" + i + "'");
throw a.code = "MODULE_NOT_FOUND", a;
}
var p = n[i] = {
exports: {}
};
Expand All @@ -148,15 +131,11 @@ exports[`plugin processes files using Browserify 1`] = `
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) o(t[i]);
return o;
}
return r;
})()({
1: [function (require, module, exports) {
Expand Down
5 changes: 5 additions & 0 deletions packages/snaps-execution-environments/.c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"reporter": ["html", "json-summary", "text", "json"],
"exclude": ["*.js", "./src/index.ts", "**/*.ava.test.ts"],
"report-dir": "./coverage-ava"
}
3 changes: 3 additions & 0 deletions packages/snaps-execution-environments/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.DS_Store
node_modules
coverage
coverage-ava
coverage-all
coverage-merged
dist
dist-temp
temp
Expand Down
9 changes: 9 additions & 0 deletions packages/snaps-execution-environments/ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = () => {
return {
concurrency: 5,
extensions: ['ts'],
require: ['ts-node/register'],
verbose: true,
files: ['src/**/*.ava.test.ts'],
};
};
3 changes: 2 additions & 1 deletion packages/snaps-execution-environments/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const deepmerge = require('deepmerge');
const baseConfig = require('../../jest.config.base');

module.exports = deepmerge(baseConfig, {
coveragePathIgnorePatterns: ['./src/index.ts'],
coveragePathIgnorePatterns: ['./src/index.ts', '.ava.test.ts'],
coverageThreshold: {
global: {
branches: 89.78,
Expand All @@ -17,4 +17,5 @@ module.exports = deepmerge(baseConfig, {
customExportConditions: ['node', 'node-addons'],
},
testTimeout: 2500,
testPathIgnorePatterns: ['.ava.test.ts'],
});
10 changes: 9 additions & 1 deletion packages/snaps-execution-environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"dist/"
],
"scripts": {
"test": "jest && yarn posttest",
"test": "yarn test:ava && jest && yarn posttest && yarn merge:coverage",
"posttest": "jest-it-up --margin 0.25",
"test:ava": "c8 ava",
"merge:coverage": "yarn mkdirp coverage-all && shx cp coverage/coverage-final.json coverage-all/coverage-final-jest.json && shx cp coverage-ava/coverage-final.json coverage-all/coverage-final-ava.json && rimraf 'coverage' 'coverage-ava' && nyc merge coverage-all coverage-merged/merged-coverage.json && nyc report -t coverage-merged --report-dir coverage --reporter=html --reporter=json-summary --reporter=json && rimraf 'coverage-merged' 'coverage-all'",
"test:ci": "yarn test",
"test:watch": "jest --watch",
"lint:eslint": "eslint . --cache --ext js,ts",
Expand Down Expand Up @@ -44,6 +46,7 @@
"superstruct": "^0.16.7"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^11.0.0",
Expand All @@ -54,6 +57,8 @@
"@types/node": "^17.0.36",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"ava": "^5.1.0",
"c8": "^7.12.0",
"concat": "^1.0.3",
"copy-webpack-plugin": "^10.2.4",
"deepmerge": "^4.2.2",
Expand All @@ -69,11 +74,14 @@
"jest-fetch-mock": "^3.0.3",
"jest-it-up": "^2.0.0",
"jsdom": "^19.0.0",
"mkdirp": "^1.0.4",
"mock-socket": "^9.1.5",
"node-polyfill-webpack-plugin": "^1.1.4",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"shx": "^0.3.4",
"ts-jest": "^29.0.0",
"ts-loader": "^9.3.1",
"typescript": "~4.8.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'ava';

import timeout from './timeout';

test('modifying handler should not be allowed and error should be thrown', (tec) => {
const { setTimeout: _setTimeout } = timeout.factory();

const handle = _setTimeout((param: unknown) => param, 100);

tec.throws(
() => {
// @ts-expect-error Ignore because this is supposed to cause an error
handle.whatever = 'something';
},
{
message: `Cannot add property whatever, object is not extensible`,
},
);
});
3 changes: 1 addition & 2 deletions packages/snaps-rollup-plugin/src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('snaps', () => {
const { code } = output[0];
expect(code).toMatchInlineSnapshot(`
"// foo bar
/* baz qux */
const foo = 'bar';
console.log(foo);
Expand Down Expand Up @@ -176,7 +175,7 @@ describe('snaps', () => {
expect(map).toMatchInlineSnapshot(`
SourceMap {
"file": "source-map.js",
"mappings": "AACEA,MAAM,CAACC,OAAP,CAAeC,YAAf,GAA8B,CAAC;EAAEC;AAAF,CAAD,KAAiB;EAC7CC,OAAO,CAACC,GAAR,CAAY,eAAZ;EAEA,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAiBJ,OAAvB;EACA,OAAOG,MAAM,GAAGC,EAAhB;AACD,CALD",
"mappings": "AACEA,MAAM,CAACC,OAAO,CAACC,YAAY,GAAG,CAAC;EAAEC;AAAO,CAAE,KAAK;EAC7CC,OAAO,CAACC,GAAG,CAAC,eAAe,CAAC;EAE5B,MAAM;IAAEC,MAAM;IAAEC;EAAI,CAAA,GAAGJ,OAAO;EAC9B,OAAOG,MAAM,GAAGC,EAAE;AACnB,CAAA",
"names": [
"module",
"exports",
Expand Down

0 comments on commit 0e1f3a7

Please sign in to comment.