Skip to content

Commit

Permalink
test: colocate test fixtures within the repo (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal authored May 23, 2021
1 parent 04196e3 commit b06309b
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 26 deletions.
1 change: 0 additions & 1 deletion .dccache

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ignore the extracted fixtures directory
__tests__/__fixtures__/tmp

# ignore dccache
.dccache

# Logs
logs
*.log
Expand Down
Binary file added __tests__/__fixtures__/simple-project.zip
Binary file not shown.
34 changes: 21 additions & 13 deletions __tests__/app.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
const fs = require('fs')
const path = require('path')
const os = require('os')
const childProcess = require('child_process')
const rimraf = require('rimraf')
const { testProject } = require('../src')

let tmpDir
const decompress = require('decompress')

beforeAll(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'snync-'))
childProcess.spawnSync('git', ['clone', '[email protected]:snyk-labs/snync-fixtures.git'], {
cwd: tmpDir
})
})
const projectFixtures = ['simple-project.zip']

const destinationFixtures = path.resolve(path.join(__dirname, '__fixtures__', 'tmp'))

afterAll(() => {
rimraf.sync(tmpDir)
beforeAll(async () => {
if (!fs.existsSync(destinationFixtures)) {
fs.mkdirSync(destinationFixtures)
}

for (const fixtureName of projectFixtures) {
const fixtureProjectPath = path.resolve(path.join(__dirname, '__fixtures__', fixtureName))
const fixtureDirectoryName = path.basename(fixtureName, '.zip')
if (fs.existsSync(path.resolve(path.join(destinationFixtures, fixtureDirectoryName)))) {
continue
} else {
await decompress(fixtureProjectPath, destinationFixtures)
}
}
})

test('integration test', async () => {
const projectPath = path.resolve(path.join(destinationFixtures, 'simple-project'))

let out = ''
await testProject(`${tmpDir}/snync-fixtures`, (...args) => (out += `${args.join(' ')}\n`))
await testProject(projectPath, (...args) => (out += `${args.join(' ')}\n`))
expect(out).toMatchSnapshot()
})
Loading

0 comments on commit b06309b

Please sign in to comment.