-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from snyk/chore/introduce-jest
chore: introduce Jest
- Loading branch information
Showing
7 changed files
with
154 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ package-lock.json | |
.nyc_output | ||
|
||
.eslintcache | ||
|
||
# Test output reports, coverage, etc | ||
reports/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
verbose: true, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverage: false, // Run yarn test:coverage to generate coverage reports | ||
collectCoverageFrom: ['lib/**/*.ts'], | ||
coverageReporters: ['html', 'text-summary'], | ||
coverageDirectory: '<rootDir>/reports/coverage', | ||
testMatch: ['**/*.spec.ts'], // Remove when all tests are using Jest | ||
modulePathIgnorePatterns: ['<rootDir>/dist', '<rootDir/reports>'], | ||
reporters: [ | ||
'default', | ||
[ | ||
'jest-junit', | ||
{ | ||
outputDirectory: '<rootDir>/reports/jest', | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { readdirSync, readFileSync } from 'fs'; | ||
import * as path from 'path'; | ||
import { applyRemediationToManifests } from '../lib'; | ||
import { chdirWorkspaces, deactivateVirtualenv } from './test-utils'; | ||
import { activateVirtualenv, pipInstall } from './test-utils'; | ||
|
||
function readDirAsFiles(dir: string) { | ||
return readdirSync(dir).reduce( | ||
(files: { [fileName: string]: string }, fileName) => { | ||
files[fileName] = readFileSync(path.join(dir, fileName), 'utf8'); | ||
return files; | ||
}, | ||
{} | ||
); | ||
} | ||
|
||
describe('remediation', () => { | ||
beforeEach(() => { | ||
activateVirtualenv('remediation'); | ||
}); | ||
|
||
afterEach(() => { | ||
deactivateVirtualenv(); | ||
}); | ||
|
||
it('fixes a pip app', async () => { | ||
chdirWorkspaces('pip-app'); | ||
pipInstall(); | ||
|
||
const upgrades = { | ||
'[email protected]': { upgradeTo: '[email protected]' }, | ||
'[email protected]': { upgradeTo: '[email protected]' }, | ||
}; | ||
|
||
const manifests = { | ||
'requirements.txt': readFileSync('requirements.txt', 'utf8'), | ||
}; | ||
|
||
const expectedUpdatedManifests = readDirAsFiles( | ||
'../../fixtures/updated-manifest' | ||
); | ||
|
||
const result = await applyRemediationToManifests( | ||
'.', | ||
manifests, | ||
upgrades, | ||
{} | ||
); | ||
|
||
expect(result).toEqual(expectedUpdatedManifests); | ||
}); | ||
|
||
it('retains python markers', async () => { | ||
chdirWorkspaces('pip-app-with-python-markers'); | ||
pipInstall(); | ||
|
||
const upgrades = { | ||
'[email protected]': { upgradeTo: '[email protected]' }, | ||
}; | ||
|
||
const manifests = { | ||
'requirements.txt': readFileSync('requirements.txt', 'utf8'), | ||
}; | ||
|
||
const expectedUpdatedManifests = readDirAsFiles( | ||
'../../fixtures/updated-manifests-with-python-markers' | ||
); | ||
|
||
const result = await applyRemediationToManifests( | ||
'.', | ||
manifests, | ||
upgrades, | ||
{} | ||
); | ||
|
||
expect(result).toEqual(expectedUpdatedManifests); | ||
}); | ||
|
||
it('handles no-op upgrades', async () => { | ||
chdirWorkspaces('pip-app'); | ||
pipInstall(); | ||
|
||
const upgrades = {}; | ||
|
||
const manifests = { | ||
'requirements.txt': readFileSync('requirements.txt', 'utf8'), | ||
}; | ||
|
||
const result = await applyRemediationToManifests( | ||
'.', | ||
manifests, | ||
upgrades, | ||
{} | ||
); | ||
|
||
expect(result).toEqual(manifests); | ||
}); | ||
|
||
it('cannot fix a Pipfile app', async () => { | ||
chdirWorkspaces('pipfile-pipapp'); | ||
|
||
const upgrades = { | ||
'[email protected]': { upgradeTo: '[email protected]' }, | ||
'[email protected]': { upgradeTo: '[email protected]' }, | ||
}; | ||
|
||
const manifests = { | ||
Pipfile: readFileSync('Pipfile', 'utf8'), | ||
}; | ||
|
||
await expect( | ||
applyRemediationToManifests('.', manifests, upgrades, {}) | ||
).rejects.toMatchObject({ | ||
message: 'Remediation only supported for requirements.txt file', | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["**/*.ts", "setup.ts"] | ||
} |