Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Oct 7, 2024
1 parent a00c826 commit b698788
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
13 changes: 11 additions & 2 deletions packages/snaps-cli/src/commands/build/implementation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { getPlatformVersion } from '@metamask/snaps-utils';
import {
DEFAULT_SNAP_BUNDLE,
DEFAULT_SNAP_ICON,
getMockSnapFilesWithUpdatedChecksum,
getPackageJson,
getSnapManifest,
} from '@metamask/snaps-utils/test-utils';
Expand Down Expand Up @@ -61,15 +64,21 @@ jest.mock('../../webpack/utils', () => ({

describe('build', () => {
beforeEach(async () => {
const { manifest } = await getMockSnapFilesWithUpdatedChecksum({
manifest: getSnapManifest({
platformVersion: getPlatformVersion(),
}),
});

await fs.mkdir('/snap');
await fs.writeFile('/snap/input.js', DEFAULT_SNAP_BUNDLE);
await fs.writeFile(
'/snap/snap.manifest.json',
JSON.stringify(getSnapManifest()),
JSON.stringify(manifest.result),
);
await fs.writeFile('/snap/package.json', JSON.stringify(getPackageJson()));
await fs.mkdir('/snap/images');
await fs.writeFile('/snap/images/icon.svg', '<svg></svg>');
await fs.writeFile('/snap/images/icon.svg', DEFAULT_SNAP_ICON);
await fs.mkdir(dirname(BROWSERSLIST_FILE), { recursive: true });
await fs.writeFile(
BROWSERSLIST_FILE,
Expand Down
26 changes: 17 additions & 9 deletions packages/snaps-cli/src/commands/manifest/implementation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { getPlatformVersion } from '@metamask/snaps-utils';
import {
DEFAULT_SNAP_BUNDLE,
DEFAULT_SNAP_ICON,
getMockSnapFilesWithUpdatedChecksum,
getPackageJson,
getSnapManifest,
} from '@metamask/snaps-utils/test-utils';
Expand Down Expand Up @@ -32,29 +35,33 @@ jest.mock('../../webpack', () => ({

describe('manifest', () => {
beforeEach(async () => {
const { manifest: newManifest } = await getMockSnapFilesWithUpdatedChecksum(
{
manifest: getSnapManifest({
platformVersion: getPlatformVersion(),
}),
},
);

await fs.mkdir('/snap/dist', { recursive: true });
await fs.writeFile('/snap/dist/bundle.js', DEFAULT_SNAP_BUNDLE);
await fs.writeFile(
'/snap/snap.manifest.json',
JSON.stringify(
getSnapManifest({
shasum: 'G/W5b2JZVv+epgNX9pkN63X6Lye9EJVJ4NLSgAw/afc=',
}),
),
JSON.stringify(newManifest.result),
);
await fs.writeFile('/snap/package.json', JSON.stringify(getPackageJson()));
await fs.mkdir('/snap/images');
await fs.writeFile('/snap/images/icon.svg', '<svg></svg>');
await fs.writeFile('/snap/images/icon.svg', DEFAULT_SNAP_ICON);
});

afterEach(async () => {
await fs.rm('/snap', { force: true, recursive: true });
});

it('validates a snap manifest', async () => {
const error = jest.spyOn(console, 'error').mockImplementation();
const error = jest.spyOn(console, 'error');
const warn = jest.spyOn(console, 'warn').mockImplementation();
const log = jest.spyOn(console, 'log').mockImplementation();
const log = jest.spyOn(console, 'log');

const spinner = ora();
const result = await manifest('/snap/snap.manifest.json', false, spinner);
Expand Down Expand Up @@ -157,7 +164,7 @@ describe('manifest', () => {
"url": "https://github.com/MetaMask/example-snap.git"
},
"source": {
"shasum": "d4W7f1lzpVGMj8jjCn1lYhhHmKc/9TSk5QLH5ldKQoI=",
"shasum": "c3Dn62ZSKu7fATN+40MhI9UqEInE9qE7u5tDjb7ylyk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -172,6 +179,7 @@ describe('manifest', () => {
"chains": ["eip155:1", "eip155:2", "eip155:3"]
}
},
"platformVersion": "6.7.0",
"manifestVersion": "0.1"
}
"
Expand Down
9 changes: 6 additions & 3 deletions packages/snaps-webpack-plugin/src/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('writeManifest', () => {
"url": "https://github.com/MetaMask/example-snap.git"
},
"source": {
"shasum": "rNyfINgNh161cBmUop+F7xlE+GSEDZH53Y/HDpGLGGg=",
"shasum": "/17SwI03+Cn9sk45Z6Czp+Sktru1oLzOmkJW+YbP9WE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -40,6 +40,7 @@ describe('writeManifest', () => {
"snap_dialog": {},
"endowment:rpc": { "snaps": true, "dapps": false }
},
"platformVersion": "1.0.0",
"manifestVersion": "0.1"
}
"
Expand All @@ -63,7 +64,7 @@ describe('writeManifest', () => {
"url": "https://github.com/MetaMask/example-snap.git"
},
"source": {
"shasum": "rNyfINgNh161cBmUop+F7xlE+GSEDZH53Y/HDpGLGGg=",
"shasum": "/17SwI03+Cn9sk45Z6Czp+Sktru1oLzOmkJW+YbP9WE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -77,6 +78,7 @@ describe('writeManifest', () => {
"snap_dialog": {},
"endowment:rpc": { "snaps": true, "dapps": false }
},
"platformVersion": "1.0.0",
"manifestVersion": "0.1"
}
"
Expand All @@ -99,7 +101,7 @@ describe('writeManifest', () => {
"url": "https://github.com/MetaMask/example-snap.git"
},
"source": {
"shasum": "rNyfINgNh161cBmUop+F7xlE+GSEDZH53Y/HDpGLGGg=",
"shasum": "/17SwI03+Cn9sk45Z6Czp+Sktru1oLzOmkJW+YbP9WE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -113,6 +115,7 @@ describe('writeManifest', () => {
"snap_dialog": {},
"endowment:rpc": { "snaps": true, "dapps": false }
},
"platformVersion": "1.0.0",
"manifestVersion": "0.1"
}
"
Expand Down

0 comments on commit b698788

Please sign in to comment.