Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legacy-tooling): use the 'targets' argument to override usual test file path #3563

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const CONFIG: CommandsConfig = {
},
{
description: 'Override the default test target for reading files.',
name: 'target',
name: 'targets',
type: 'string',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const PATTERNS = {
* Test directories for organizing test runners.
*/
const TEST_DIRECTORIES = {
INTEGRATION: './integration',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good , need the intergation and coverage to be fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are fixed now.

INTEGRATION: './integration/spec',
ROOT: './test',
UNIT: './unit',
UNIT: './unit/spec',
};

const CONSTANTS = {
Expand Down
16 changes: 12 additions & 4 deletions packages/legacy/tools/src/models/package/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class Package {
const inputPath = path.join(this.data.packageRoot, source);

const javascriptFileCollector = javascript
? Package.getFiles({ location: inputPath, pattern: CONSTANTS.PATTERNS.JAVASCRIPT })
? Package.getFiles({ location: inputPath, pattern: CONSTANTS.PATTERNS.JAVASCRIPT, targets: undefined })
: Promise.resolve([]);

const typescriptFileCollector = typescript
? Package.getFiles({ location: inputPath, pattern: CONSTANTS.PATTERNS.TYPESCRIPT })
? Package.getFiles({ location: inputPath, pattern: CONSTANTS.PATTERNS.TYPESCRIPT, targets: undefined })
: Promise.resolve([]);

return Promise.all([javascriptFileCollector, typescriptFileCollector])
Expand Down Expand Up @@ -104,13 +104,15 @@ class Package {
? Package.getFiles({
location: path.join(testDirectory, CONSTANTS.TEST_DIRECTORIES.UNIT),
pattern: CONSTANTS.PATTERNS.TEST,
targets: config.targets,
})
: Promise.resolve([]);

const integrationTestFileCollector = config.integration
? Package.getFiles({
location: path.join(testDirectory, CONSTANTS.TEST_DIRECTORIES.INTEGRATION),
pattern: CONSTANTS.PATTERNS.TEST,
targets: config.targets,
})
: Promise.resolve([]);

Expand Down Expand Up @@ -155,8 +157,14 @@ class Package {
* @param options - Options for getting files.
* @returns - Promise resolving to an Array of file paths.
*/
protected static getFiles({ location, pattern }: { location: string, pattern: string }): Promise<Array<string>> {
const target = path.join(location, pattern);
protected static getFiles({ location, pattern, targets }:
{ location: string, pattern: string, targets: string | undefined }): Promise<Array<string>> {
let target;
if (!targets) {
target = path.join(location, pattern);
} else {
target = path.join(location, targets);
}

return glob.glob(target);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/legacy/tools/test/integration/package/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ describe('Package', () => {
pattern: 'example/pattern',
};

const configWithTargets = {
location: 'example/location',
pattern: 'example/pattern',
targets: 'sampleTestFile.js',
};

const results = {
glob: {
glob: [
Expand All @@ -332,6 +338,15 @@ describe('Package', () => {
expect(spies.path.join).toHaveBeenCalledOnceWith(config.location, config.pattern);
}));

it('should call "path.join()" with the provided location, pattern and targets', () => Package.getFiles(configWithTargets)
.then(() => {
expect(spies.path.join).toHaveBeenCalledOnceWith(
configWithTargets.location,
configWithTargets.pattern,
configWithTargets.targets,
);
}));

it('should call "glob.glob()" with the merged target', () => {
const target = path.join(config.location, config.pattern);

Expand Down
Loading