forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckTarball.test.js
53 lines (47 loc) · 1.19 KB
/
checkTarball.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-env jest, node, es2021 */
/**
* Make sure tarballs don't change from under us.
*/
const { spawnSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const fg = require('fast-glob')
/**
* This line at the end tends to vary:
*
* ```
* ➤ YN0000: Done in 0s 22ms
* ```
*
* Let's get rid of it before matching.
*
* @param {string} workspace
*/
async function getTarballContents(workspace) {
const child = spawnSync(
`yarn workspace @redwoodjs/${workspace} pack --dry-run`,
{
shell: true,
cwd: process.env.PROJECT_CWD,
}
)
return child.stdout
.toString()
.trim()
.split('\n')
.filter((line) => !line.includes('Done in'))
}
const { workspaces: workspacesGlob } = JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json'))
)
const workspaces = fg
.sync(workspacesGlob, { onlyDirectories: true })
.map((workspace) => workspace.match(/packages\/(?<name>.+)/).groups.name)
describe('tarballs', () => {
for (const workspace of workspaces) {
it(workspace, async () => {
const tarballContents = await getTarballContents(workspace)
expect(tarballContents).toMatchSnapshot()
})
}
})