-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f46360
commit 1979e6a
Showing
18 changed files
with
167 additions
and
8 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[ignore] | ||
.*/__fixtures__/.* | ||
|
||
[include] | ||
|
||
|
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
__fixtures__/simple-project-with-excluded-package/package.json
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,9 @@ | ||
{ | ||
"private": true, | ||
"name": "simple-project", | ||
"version": "1.0.0", | ||
"pworkspaces": [ | ||
"packages/*", | ||
"!packages/bar" | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
__fixtures__/simple-project-with-excluded-package/packages/bar/package.json
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 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
__fixtures__/simple-project-with-excluded-package/packages/foo/package.json
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 @@ | ||
{ | ||
"name": "bar", | ||
"version": "1.0.0" | ||
} |
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,8 @@ | ||
{ | ||
"private": true, | ||
"name": "simple-project", | ||
"version": "1.0.0", | ||
"pworkspaces": [ | ||
"packages/*" | ||
] | ||
} |
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 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0" | ||
} |
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 @@ | ||
{ | ||
"name": "bar", | ||
"version": "1.0.0" | ||
} |
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,14 +1,34 @@ | ||
// @flow | ||
import install from '../install'; | ||
import * as processes from '../../utils/processes'; | ||
|
||
const unsafeProcesses: any = processes; | ||
import * as path from 'path'; | ||
import * as fs from '../../utils/fs'; | ||
import {getFixturePath} from 'jest-fixtures'; | ||
|
||
jest.mock('../../utils/processes'); | ||
jest.mock('../../utils/logger'); | ||
jest.unmock('../install'); | ||
|
||
test('pyarn install', async () => { | ||
await install([], {}); | ||
const unsafeProcesses: any & typeof processes = processes; | ||
|
||
describe('install', () => { | ||
let readdirSpy; | ||
|
||
beforeEach(() => { | ||
readdirSpy = jest.spyOn(fs, 'readdir').mockImplementation(() => Promise.resolve([])); | ||
}); | ||
|
||
afterEach(() => { | ||
readdirSpy.mockRestore(); | ||
}); | ||
|
||
console.log(unsafeProcesses.spawn.mock.calls); | ||
test('simple-package', async () => { | ||
let cwd = await getFixturePath(__dirname, 'simple-package'); | ||
await install([], { cwd }); | ||
expect(unsafeProcesses.spawn).toHaveBeenCalledWith( | ||
'yarn', | ||
['install', '--non-interactive', '-s'], | ||
{ cwd } | ||
); | ||
}); | ||
}); |
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
3 changes: 3 additions & 0 deletions
3
src/utils/__fixtures__/package-with-four-spaces-json/package.json
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,3 @@ | ||
{ | ||
"name": "four-spaces" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/utils/__fixtures__/package-with-invalid-json/package.json
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,3 @@ | ||
{ | ||
"name": "invalid | ||
} |
3 changes: 3 additions & 0 deletions
3
src/utils/__fixtures__/package-with-uncertain-indentation-json/package.json
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,3 @@ | ||
{ | ||
"name": "four-spaces" | ||
} |
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,88 @@ | ||
// @flow | ||
import * as config from '../config'; | ||
import * as fs from '../fs'; | ||
import {mkdtempSync} from 'fs'; | ||
import * as path from 'path'; | ||
import {getFixturePath} from 'jest-fixtures'; | ||
|
||
const FIXTURES_DIR = path.resolve(__dirname, '..', '..', '..', '__fixtures__'); | ||
|
||
describe('readConfigFile', () => { | ||
it('should read a valid package.json file', async () => { | ||
let filePath = await getFixturePath(__dirname, 'simple-package', 'package.json'); | ||
let pkg = await config.readConfigFile(filePath); | ||
expect(pkg).toMatchObject({ | ||
name: 'fixture-basic', | ||
}); | ||
}); | ||
|
||
it('should error on an invalid package.json file', async () => { | ||
let filePath = await getFixturePath(__dirname, 'package-with-invalid-json', 'package.json'); | ||
return expect(config.readConfigFile(filePath)).rejects.toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('writeConfigFile', () => { | ||
let spy; | ||
|
||
beforeEach(() => { | ||
spy = jest.spyOn(fs, 'writeFile').mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
spy.mockRestore(); | ||
}); | ||
|
||
it('should write a json file', async () => { | ||
let filePath = await getFixturePath(__dirname, 'simple-package', 'package.json'); | ||
let pkg = { name: 'wat', version: '0.0.0' }; | ||
await config.writeConfigFile(filePath, pkg); | ||
expect(fs.writeFile).toHaveBeenCalledWith(filePath, JSON.stringify(pkg, null, 2)); | ||
}); | ||
|
||
it('should write a json file with correct-indentation', async () => { | ||
let filePath = await getFixturePath(__dirname, 'package-with-four-spaces-json', 'package.json'); | ||
let pkg = { name: 'wat', version: '0.0.0' }; | ||
await config.writeConfigFile(filePath, pkg); | ||
expect(fs.writeFile).toHaveBeenCalledWith(filePath, JSON.stringify(pkg, null, 4)); | ||
}); | ||
|
||
it('should write a json file with correct-indentation when uncertain', async () => { | ||
let filePath = await getFixturePath(__dirname, 'package-with-uncertain-indentation-json', 'package.json'); | ||
let pkg = { name: 'wat', version: '0.0.0' }; | ||
await config.writeConfigFile(filePath, pkg); | ||
expect(fs.writeFile).toHaveBeenCalledWith(filePath, JSON.stringify(pkg, null, 2)); | ||
}); | ||
}); | ||
|
||
describe('getProjectConfig()', () => { | ||
it('should get the root if it is the current directory', async () => { | ||
let fixturePath = await getFixturePath(__dirname, 'simple-project'); | ||
let found = await config.getProjectConfig(fixturePath); | ||
expect(found).toBe(path.join(fixturePath, 'package.json')); | ||
}); | ||
|
||
it('should get the root if in nested non-package directory', async () => { | ||
let fixturePath = await getFixturePath(__dirname, 'simple-project', 'packages'); | ||
let found = await config.getProjectConfig(fixturePath); | ||
expect(found).toBe(path.join(fixturePath, '..', 'package.json')); | ||
}); | ||
|
||
it('should get the root if in nested package directory', async () => { | ||
let fixturePath = await getFixturePath(__dirname, 'simple-project', 'packages', 'bar'); | ||
let found = await config.getProjectConfig(fixturePath); | ||
expect(found).toBe(path.join(fixturePath, '..', '..', 'package.json')); | ||
}); | ||
|
||
it('should return null if in non-package directory', async () => { | ||
let tempPath = mkdtempSync('/tmp/non-package-'); | ||
let found = await config.getProjectConfig(tempPath); | ||
expect(found).toBe(null); | ||
}); | ||
|
||
it('should get the root if in nested package not included in a parent project', async () => { | ||
let fixturePath = await getFixturePath(__dirname, 'simple-project-with-excluded-package', 'packages', 'bar'); | ||
let found = await config.getProjectConfig(fixturePath); | ||
expect(found).toBe(path.join(fixturePath, 'package.json')); | ||
}); | ||
}); |
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