This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Maxim
authored
Feb 18, 2021
1 parent
7edfd5e
commit 95b4db8
Showing
15 changed files
with
166 additions
and
31 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
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
40 changes: 40 additions & 0 deletions
40
core/garment/__tests__/__snapshots__/getProjectsByName.test.ts.snap
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,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getProjectsByName returns projects if files flag is unspecified 1`] = ` | ||
Array [ | ||
"project-a", | ||
"project-c", | ||
] | ||
`; | ||
|
||
exports[`getProjectsByName returns projects matching glob pattern 1`] = ` | ||
Array [ | ||
"project-a", | ||
"project-b", | ||
"project-c", | ||
] | ||
`; | ||
|
||
exports[`getProjectsByName returns projects with files if files flag is specified 1`] = ` | ||
Array [ | ||
Object { | ||
"files": Array [ | ||
"/test_path/project-a/a1.txt", | ||
"/test_path/project-a/a2.txt", | ||
], | ||
"projectPath": "project-a", | ||
}, | ||
Object { | ||
"files": Array [ | ||
"/test_path/project-c/c2.txt", | ||
], | ||
"projectPath": "project-c", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`getProjectsByName throws if no projects are matching glob pattern 1`] = `"Projects matching \\"project-*\\" were not found"`; | ||
|
||
exports[`getProjectsByName throws if the project name is not found 1`] = `"Project with path \\"proj-d\\" was not found"`; | ||
|
||
exports[`getProjectsByName throws in the project containing file is not found 1`] = `"Project containing file \\"/project-X/non-existing-file.txt\\" was not found"`; |
13 changes: 13 additions & 0 deletions
13
core/garment/__tests__/fixtures/basic-workspace/garment.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,13 @@ | ||
{ | ||
"projects": { | ||
"proj-a": { | ||
"path": "project-a" | ||
}, | ||
"proj-b": { | ||
"path": "project-b" | ||
}, | ||
"proj-c": { | ||
"path": "project-c" | ||
} | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,87 @@ | ||
import { initFixtureHelper, replaceTestPath } from '@garment/fixture-helper'; | ||
import { Workspace } from '@garment/workspace'; | ||
import * as Path from 'path'; | ||
import { getProjectsByName } from '../src'; | ||
|
||
const { initFixture, clean } = initFixtureHelper(module, { | ||
tempDir: Path.join(__dirname, '/tmp__') | ||
}); | ||
|
||
const initFixtureWorkspace = async () => { | ||
const testDir = await initFixture('basic-workspace'); | ||
|
||
const workspace = Workspace.create( | ||
require(Path.join(testDir, 'garment.json')), | ||
{ cwd: testDir } | ||
); | ||
|
||
return workspace; | ||
}; | ||
|
||
afterAll(clean); | ||
|
||
describe('getProjectsByName', () => { | ||
test('returns projects if files flag is unspecified', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
|
||
const result = getProjectsByName(workspace, ['proj-a', 'proj-c']); | ||
expect(result.map(({ project }) => project.path)).toMatchSnapshot(); | ||
}); | ||
|
||
test('throws if the project name is not found', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
expect(() => | ||
getProjectsByName(workspace, ['proj-a', 'proj-d']) | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('returns projects with files if files flag is specified', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
|
||
const files = [ | ||
'project-a/a1.txt', | ||
'project-a/a2.txt', | ||
'project-c/c2.txt' | ||
].map(_ => workspace.resolvePath(_)); | ||
|
||
const result = getProjectsByName(workspace, files, true); | ||
expect( | ||
replaceTestPath( | ||
result.map(item => ({ | ||
projectPath: item.project.path, | ||
files: item.files | ||
})), | ||
workspace.cwd | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('throws in the project containing file is not found', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
expect(() => | ||
getProjectsByName( | ||
workspace, | ||
[workspace.resolvePath('/project-X/non-existing-file.txt')], | ||
true | ||
) | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('returns projects matching glob pattern', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
try { | ||
const result = getProjectsByName(workspace, ['proj-*']); | ||
expect(result.map(({ project }) => project.path)).toMatchSnapshot(); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}); | ||
|
||
|
||
test('throws if no projects are matching glob pattern', async () => { | ||
const workspace = await initFixtureWorkspace(); | ||
expect(() => | ||
getProjectsByName(workspace, ['project-*']) | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -50,7 +50,6 @@ | |
"lint-staged": { | ||
"*.{ts,tsx}": [ | ||
"prettier --write", | ||
"eslint --fix", | ||
"git add" | ||
] | ||
}, | ||
|