Skip to content

Commit

Permalink
test(cli): test for contents of tarball instead of size
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2022
1 parent b313869 commit 79e6c1e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/@sanity/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@
"@sanity/generate-help-url": "^3.0.0",
"@sanity/types": "3.0.0-dev-preview.20",
"@sanity/util": "3.0.0-dev-preview.20",
"@types/babel__traverse": "^7.18.1",
"@types/configstore": "^5.0.1",
"@types/cpx": "^1.5.2",
"@types/babel__traverse": "^7.18.1",
"@types/decompress": "^4.2.4",
"@types/eventsource": "^1.1.8",
"@types/inquirer": "^6.0.0",
"@types/node": "^14.18.9",
"@types/semver-compare": "^1.0.1",
"@types/tar": "^6.1.3",
"@types/validate-npm-package-name": "^3.0.3",
"@types/which": "^2.0.1",
"babylon": "^6.18.0",
Expand Down Expand Up @@ -100,6 +101,7 @@
"rimraf": "^3.0.2",
"semver": "^7.3.5",
"semver-compare": "^1.0.0",
"tar": "^6.1.11",
"validate-npm-package-name": "^3.0.0",
"which": "^2.0.2",
"xdg-basedir": "^4.0.0"
Expand Down
17 changes: 15 additions & 2 deletions packages/@sanity/cli/test/exportImport.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'
import {stat} from 'fs/promises'
import tar from 'tar'
import {describeCliTest, testConcurrent} from './shared/describe'
import {
getTestRunArgs,
Expand All @@ -23,9 +24,21 @@ describeCliTest('CLI: `sanity dataset export` / `import`', () => {
expect(result.stdout).toMatch(/export finished/i)
expect(result.code).toBe(0)

const stats = await stat(path.join(studiosPath, version, testRunArgs.exportTarball))
const tarballPath = path.join(studiosPath, version, testRunArgs.exportTarball)

const stats = await stat(tarballPath)
expect(stats.isFile()).toBe(true)
expect(stats.size).toBeGreaterThanOrEqual(5000)

// We're just checking for the existence of a few files here - the actual export
// functionality is fully tested in `@sanity/export`
const filesTypes: string[] = []
await tar.t({
file: tarballPath,
onentry: (entry) => filesTypes.push(path.extname(entry.path)),
})

expect(filesTypes).toContain('.ndjson')
expect(filesTypes).toContain('.jpg')
})

testConcurrent('import', async () => {
Expand Down
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4357,6 +4357,14 @@
dependencies:
"@types/node" "*"

"@types/tar@^6.1.3":
version "6.1.3"
resolved "https://registry.yarnpkg.com/@types/tar/-/tar-6.1.3.tgz#46a2ce7617950c4852dfd7e9cd41aa8161b9d750"
integrity sha512-YzDOr5kdAeqS8dcO6NTTHTMJ44MUCBDoLEIyPtwEn7PssKqUYL49R1iCVJPeiPzPlKi6DbH33eZkpeJ27e4vHg==
dependencies:
"@types/node" "*"
minipass "^3.3.5"

"@types/testing-library__jest-dom@^5.9.1":
version "5.14.5"
resolved "https://registry.yarnpkg.com/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.14.5.tgz#d113709c90b3c75fdb127ec338dad7d5f86c974f"
Expand Down Expand Up @@ -12797,6 +12805,13 @@ minipass@^3.0.0, minipass@^3.1.0, minipass@^3.1.1, minipass@^3.1.3:
dependencies:
yallist "^4.0.0"

minipass@^3.3.5:
version "3.3.5"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.3.5.tgz#6da7e53a48db8a856eeb9153d85b230a2119e819"
integrity sha512-rQ/p+KfKBkeNwo04U15i+hOwoVBVmekmm/HcfTkTN2t9pbQKCMm4eN5gFeqgrrSp/kH/7BYYhTIHOxGqzbBPaA==
dependencies:
yallist "^4.0.0"

minizlib@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.3.tgz#2290de96818a34c29551c8a8d301216bd65a861d"
Expand Down Expand Up @@ -17145,7 +17160,7 @@ tar@^4.4.12:
safe-buffer "^5.2.1"
yallist "^3.1.1"

tar@^6.0.2, tar@^6.1.0:
tar@^6.0.2, tar@^6.1.0, tar@^6.1.11:
version "6.1.11"
resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621"
integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==
Expand Down

0 comments on commit 79e6c1e

Please sign in to comment.