Skip to content

Commit

Permalink
Fix (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-vasin authored Feb 19, 2021
1 parent 6c4da02 commit 373a4fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const processWorkspaces = async (
debug(output)
const info = JSON.parse(output)
const workspaces = Object.keys(info).map((name) => {
const location = path.resolve(info[name].location)
const location = path.resolve(cwd, info[name].location)
debug(`[${name}] enqueue processing at ${location}`)
return {
name,
Expand Down
53 changes: 41 additions & 12 deletions common/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { mocked } from 'ts-jest/utils'
import { execSync } from 'child_process'
import { readFileSync } from 'fs'
import * as path from 'path'
import * as process from 'process'
import {
bumpDependencies,
Expand Down Expand Up @@ -112,18 +111,18 @@ describe('processWorkspaces', () => {
beforeEach(() => {
output = JSON.stringify({
'package-a': {
location: '/path/to/a',
location: 'path/to/a',
},
'package-b': {
location: '/path/to/b',
location: 'path/to/b',
},
})
mExec.mockReturnValue(Buffer.from(output))
processor = jest.fn()
mReadFile.mockImplementation((file) =>
Buffer.from(
JSON.stringify({
name: path.dirname(file.toString()),
name: file,
})
)
)
Expand All @@ -148,29 +147,59 @@ describe('processWorkspaces', () => {
})
})

test('processor invoked for each workspace', async () => {
test('processor invoked for each workspace in current working directory', async () => {
await processWorkspaces(processor, jest.fn())

expect(processor).toHaveBeenCalledWith({
name: 'package-a',
location: '/path/to/a',
location: `${process.cwd()}/path/to/a`,
pkg: {
name: '/path/to/a',
name: `${process.cwd()}/path/to/a/package.json`,
},
})
expect(processor).toHaveBeenCalledWith({
name: 'package-b',
location: '/path/to/b',
location: `${process.cwd()}/path/to/b`,
pkg: {
name: '/path/to/b',
name: `${process.cwd()}/path/to/b/package.json`,
},
})
})

test('package.json files read', async () => {
test('package.json files read in current working directory', async () => {
await processWorkspaces(processor, jest.fn())

expect(mReadFile).toHaveBeenCalledWith(`/path/to/a/package.json`)
expect(mReadFile).toHaveBeenCalledWith(`/path/to/b/package.json`)
expect(mReadFile).toHaveBeenCalledWith(
`${process.cwd()}/path/to/a/package.json`
)
expect(mReadFile).toHaveBeenCalledWith(
`${process.cwd()}/path/to/b/package.json`
)
})

test('processor invoked for each workspace in specified directory', async () => {
await processWorkspaces(processor, jest.fn(), '/specified')

expect(processor).toHaveBeenCalledWith({
name: 'package-a',
location: `/specified/path/to/a`,
pkg: {
name: `/specified/path/to/a/package.json`,
},
})
expect(processor).toHaveBeenCalledWith({
name: 'package-b',
location: `/specified/path/to/b`,
pkg: {
name: `/specified/path/to/b/package.json`,
},
})
})

test('package.json files read in specified directory', async () => {
await processWorkspaces(processor, jest.fn(), '/specified')

expect(mReadFile).toHaveBeenCalledWith(`/specified/path/to/a/package.json`)
expect(mReadFile).toHaveBeenCalledWith(`/specified/path/to/b/package.json`)
})
})

0 comments on commit 373a4fd

Please sign in to comment.