-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): improve tests, fixtures, and refactor
- Loading branch information
1 parent
2684490
commit 7ff66d4
Showing
33 changed files
with
805 additions
and
436 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'expect-more-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { readJsonSync } from 'fs-extra'; | ||
import mock = require('mock-fs'); | ||
import { getFixture, getMockCommander } from '../test/helpers'; | ||
import { run } from './fix-mismatches'; | ||
import { IManifest } from './typings'; | ||
|
||
describe('fix-mismatches', () => { | ||
let spyConsole: any; | ||
|
||
afterAll(() => { | ||
mock.restore(); | ||
}); | ||
|
||
beforeAll(async () => { | ||
const [one, two, three] = getFixture('exact').data as IManifest[]; | ||
const sources = [ | ||
'/path/1/package.json', | ||
'/path/2/package.json', | ||
'/path/3/package.json' | ||
]; | ||
const program = getMockCommander(sources); | ||
mock({ | ||
'/path/1/package.json': JSON.stringify(one), | ||
'/path/2/package.json': JSON.stringify(two), | ||
'/path/3/package.json': JSON.stringify(three) | ||
}); | ||
const noop = () => undefined; | ||
spyConsole = jest.spyOn(console, 'log').mockImplementation(noop); | ||
await run(program); | ||
}); | ||
|
||
it('sets the version of dependencies with different versions to the newest of those versions found', () => { | ||
expect(readJsonSync('/path/1/package.json')).toEqual( | ||
expect.objectContaining({ | ||
dependencies: { chalk: '2.3.0', commander: '2.13.0' }, | ||
devDependencies: { | ||
jest: '22.1.4', | ||
prettier: '1.10.2', | ||
rimraf: '2.6.2' | ||
}, | ||
peerDependencies: { gulp: '*' } | ||
}) | ||
); | ||
expect(readJsonSync('/path/2/package.json')).toEqual( | ||
expect.objectContaining({ | ||
dependencies: { chalk: '2.3.0' }, | ||
devDependencies: { jest: '22.1.4' } | ||
}) | ||
); | ||
expect(readJsonSync('/path/3/package.json')).toEqual( | ||
expect.objectContaining({ | ||
devDependencies: { | ||
npm: 'https://github.com/npm/npm.git', | ||
prettier: '1.10.2' | ||
}, | ||
peerDependencies: { gulp: '*' } | ||
}) | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,107 +1,108 @@ | ||
import { getUntidyManifest } from '../test/fixtures'; | ||
import { shuffleObject } from '../test/helpers'; | ||
import { readJsonSync } from 'fs-extra'; | ||
import mock = require('mock-fs'); | ||
import { getFixture, getMockCommander, shuffleObject } from '../test/helpers'; | ||
import { SORT_FIRST } from './constants'; | ||
import { run } from './format'; | ||
import { IManifest } from './typings'; | ||
import { manifestData } from './manifests/manifest-data'; | ||
|
||
describe('format', () => { | ||
let results: IManifest[]; | ||
beforeAll(() => { | ||
results = manifestData.format([ | ||
shuffleObject(getUntidyManifest()) as IManifest | ||
let minimal: IManifest; | ||
let untidy: IManifest; | ||
|
||
beforeAll(async () => { | ||
const program = getMockCommander([ | ||
'/minimal/package.json', | ||
'/untidy/package.json' | ||
]); | ||
mock({ | ||
'/minimal/package.json': JSON.stringify({ | ||
name: 'minimal', | ||
version: '0.0.0' | ||
}), | ||
'/untidy/package.json': getFixture('untidy', shuffleObject).json | ||
}); | ||
await run(program); | ||
minimal = readJsonSync('/minimal/package.json'); | ||
untidy = readJsonSync('/untidy/package.json'); | ||
mock.restore(); | ||
}); | ||
|
||
it('sorts specified keys to the top of package.json', () => { | ||
results.forEach((result) => { | ||
expect(Object.keys(result).slice(0, SORT_FIRST.length)).toEqual( | ||
SORT_FIRST | ||
); | ||
}); | ||
expect(Object.keys(untidy).slice(0, SORT_FIRST.length)).toEqual(SORT_FIRST); | ||
}); | ||
|
||
it('sorts remaining keys alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(Object.keys(result).slice(SORT_FIRST.length - 1)).toEqual([ | ||
'author', | ||
'bin', | ||
'bugs', | ||
'dependencies', | ||
'devDependencies', | ||
'files', | ||
'homepage', | ||
'keywords', | ||
'license', | ||
'main', | ||
'peerDependencies', | ||
'repository', | ||
'scripts' | ||
]); | ||
}); | ||
expect(Object.keys(untidy).slice(SORT_FIRST.length - 1)).toEqual([ | ||
'author', | ||
'bin', | ||
'bugs', | ||
'dependencies', | ||
'devDependencies', | ||
'files', | ||
'homepage', | ||
'keywords', | ||
'license', | ||
'main', | ||
'peerDependencies', | ||
'repository', | ||
'scripts' | ||
]); | ||
}); | ||
|
||
it('sorts "dependencies" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.dependencies).toEqual({ | ||
arnold: '5.0.0', | ||
dog: '2.13.0', | ||
guybrush: '7.1.1', | ||
mango: '2.3.0' | ||
}); | ||
expect(minimal).not.toHaveProperty('dependencies'); | ||
expect(untidy.dependencies).toEqual({ | ||
arnold: '5.0.0', | ||
dog: '2.13.0', | ||
guybrush: '7.1.1', | ||
mango: '2.3.0' | ||
}); | ||
}); | ||
|
||
it('sorts "devDependencies" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.devDependencies).toEqual({ | ||
stroopwafel: '4.4.2', | ||
waldorf: '22.1.4' | ||
}); | ||
expect(minimal).not.toHaveProperty('devDependencies'); | ||
expect(untidy.devDependencies).toEqual({ | ||
stroopwafel: '4.4.2', | ||
waldorf: '22.1.4' | ||
}); | ||
}); | ||
|
||
it('sorts "files" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.files).toEqual(['assets', 'dist']); | ||
}); | ||
expect(minimal).not.toHaveProperty('files'); | ||
expect(untidy.files).toEqual(['assets', 'dist']); | ||
}); | ||
|
||
it('sorts "keywords" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.keywords).toEqual(['thing', 'those', 'whatsits']); | ||
}); | ||
expect(minimal).not.toHaveProperty('keywords'); | ||
expect(untidy.keywords).toEqual(['thing', 'those', 'whatsits']); | ||
}); | ||
|
||
it('sorts "peerDependencies" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.peerDependencies).toEqual({ | ||
giftwrap: '0.1.2', | ||
jambalaya: '6.1.4', | ||
zoolander: '1.4.25' | ||
}); | ||
expect(minimal).not.toHaveProperty('peerDependencies'); | ||
expect(untidy.peerDependencies).toEqual({ | ||
giftwrap: '0.1.2', | ||
jambalaya: '6.1.4', | ||
zoolander: '1.4.25' | ||
}); | ||
}); | ||
|
||
it('sorts "scripts" alphabetically', () => { | ||
results.forEach((result) => { | ||
expect(result.scripts).toEqual({ | ||
build: 'tsc', | ||
format: 'prettier', | ||
lint: 'tslint', | ||
test: 'jest' | ||
}); | ||
expect(minimal).not.toHaveProperty('scripts'); | ||
expect(untidy.scripts).toEqual({ | ||
build: 'tsc', | ||
format: 'prettier', | ||
lint: 'tslint', | ||
test: 'jest' | ||
}); | ||
}); | ||
|
||
it('uses shorthand "bugs"', () => { | ||
results.forEach((result) => { | ||
expect(result.bugs).toEqual('https://github.com/JaneDoe/do-it/issues'); | ||
}); | ||
expect(minimal).not.toHaveProperty('bugs'); | ||
expect(untidy.bugs).toEqual('https://github.com/JaneDoe/do-it/issues'); | ||
}); | ||
|
||
it('uses shorthand "repository"', () => { | ||
results.forEach((result) => { | ||
expect(result.repository).toEqual('JaneDoe/do-it'); | ||
}); | ||
expect(minimal).not.toHaveProperty('repository'); | ||
expect(untidy.repository).toEqual('JaneDoe/do-it'); | ||
}); | ||
}); |
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
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
Oops, something went wrong.