Skip to content

Commit

Permalink
fix(legacy-tooling): use the 'targets' argument to override usual tes…
Browse files Browse the repository at this point in the history
…t file path (#3563)
  • Loading branch information
sreenara authored Apr 25, 2024
1 parent 5984fbc commit b81ca4a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 32 deletions.
50 changes: 27 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

This project is open for contributions. This article serves as an entrypoint to begin contributing to this project.

* [Reporting an Issue](#reporting-an-issue)
* [Providing Contributions](#providing-contributions)
* [Setup](#setup)
* [Requirements](#requirements)
* [Downloading](#downloading)
* [Environment](#environment)
* [Dependencies](#dependencies)
* [Prebuilding](#prebuilding)
* [Contribute](#contribute)
* [Project Changes](#project-changes)
* [Automation](#automation)
* [Configuration](#configuration)
* [Modern Configuration](#modern-configuration)
* [Legacy Configuration](#legacy-configuration)
* [Documentation](#documentation)
* [General Documentation](#general-documentation)
* [Samples Documentation](#samples-documentation)
* [Module Changes](#module-changes)
* [Creating](#creating)
* [Building](#building)
* [Testing](#testing)
* [Submitting Changes](#submitting-changes)
* [Requesting Support](#requesting-support)
- [Contributing](#contributing)
- [Reporting an Issue](#reporting-an-issue)
- [Providing Contributions](#providing-contributions)
- [Setup](#setup)
- [Requirements](#requirements)
- [Downloading](#downloading)
- [Environment](#environment)
- [Dependencies](#dependencies)
- [Prebuilding](#prebuilding)
- [Contribute](#contribute)
- [Project Changes](#project-changes)
- [Automation](#automation)
- [Configuration](#configuration)
- [Modern Configuration](#modern-configuration)
- [Legacy Configuration](#legacy-configuration)
- [Documentation](#documentation)
- [General Documentation](#general-documentation)
- [Samples Documentation](#samples-documentation)
- [Module Changes](#module-changes)
- [Creating](#creating)
- [Building](#building)
- [Testing](#testing)
- [Submitting Changes](#submitting-changes)
- [Requesting Support](#requesting-support)

## Reporting an Issue

Expand Down Expand Up @@ -256,6 +257,9 @@ Running tests against a module can be performed by using the following commands
* `yarn workspace {module-name} test:syntax` - Run syntax tests.
* `yarn workspace {module-name} test:browser` - Run browser tests.

**Note:** To run individual test files, use the `--targets` option along with the test command. An example is shown below:
* `yarn workspace {module name} test:unit --targets {filename}` - Run the unit test only for the target filename.

#### Submitting Changes

When submitting changes to this project, all changes must go through the [GitHub Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) process. Below are the steps outlining the process:
Expand Down
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
4 changes: 2 additions & 2 deletions packages/legacy/tools/src/models/package/package.constants.ts
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',
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
23 changes: 23 additions & 0 deletions packages/legacy/tools/test/integration/package/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(pack.data.packageRoot, config.source),
pattern: './**/*.js',
targets: undefined,
}]);
}));

Expand All @@ -76,6 +77,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(pack.data.packageRoot, config.source),
pattern: './**/*.ts',
targets: undefined,
}]);
}));

Expand All @@ -84,6 +86,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[1].args).toEqual([{
location: path.join(pack.data.packageRoot, config.source),
pattern: './**/*.ts',
targets: undefined,
}]);
}));

Expand All @@ -93,6 +96,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(pack.data.packageRoot, config.source),
pattern: './**/*.js',
targets: undefined,
}]);
}));

Expand Down Expand Up @@ -133,6 +137,7 @@ describe('Package', () => {
config = {
integration: true,
unit: true,
targets: 'sampleFile.ts',
};

spies.Package = {
Expand Down Expand Up @@ -175,6 +180,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(testDirectory, Package.CONSTANTS.TEST_DIRECTORIES.UNIT),
pattern: Package.CONSTANTS.PATTERNS.TEST,
targets: config.targets,
}]);
});
});
Expand All @@ -193,6 +199,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(testDirectory, Package.CONSTANTS.TEST_DIRECTORIES.INTEGRATION),
pattern: Package.CONSTANTS.PATTERNS.TEST,
targets: config.targets,
}]);
});
});
Expand All @@ -208,6 +215,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[1].args).toEqual([{
location: path.join(testDirectory, Package.CONSTANTS.TEST_DIRECTORIES.INTEGRATION),
pattern: Package.CONSTANTS.PATTERNS.TEST,
targets: config.targets,
}]);
});
});
Expand All @@ -226,6 +234,7 @@ describe('Package', () => {
expect(spies.Package.getFiles.calls.all()[0].args).toEqual([{
location: path.join(testDirectory, Package.CONSTANTS.TEST_DIRECTORIES.UNIT),
pattern: Package.CONSTANTS.PATTERNS.TEST,
targets: config.targets,
}]);
});
});
Expand Down Expand Up @@ -306,6 +315,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 +347,14 @@ describe('Package', () => {
expect(spies.path.join).toHaveBeenCalledOnceWith(config.location, config.pattern);
}));

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('runTests', () => {
expect(found.type).toBe('array');
});

it('should include the fully qualified "target" option', () => {
const found = runTests.config.options.find((option) => option.name === 'target');
it('should include the fully qualified "targets" option', () => {
const found = runTests.config.options.find((option) => option.name === 'targets');

expect(!!found).toBeTrue();
expect(typeof found.description).toBe('string');
Expand Down

0 comments on commit b81ca4a

Please sign in to comment.