diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e474c1e2754..31fe0b5aedd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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: diff --git a/packages/legacy/tools/src/commands/run-tests/run-tests.constants.ts b/packages/legacy/tools/src/commands/run-tests/run-tests.constants.ts index 9824a85ce6b..64c3f4be4af 100644 --- a/packages/legacy/tools/src/commands/run-tests/run-tests.constants.ts +++ b/packages/legacy/tools/src/commands/run-tests/run-tests.constants.ts @@ -45,7 +45,7 @@ const CONFIG: CommandsConfig = { }, { description: 'Override the default test target for reading files.', - name: 'target', + name: 'targets', type: 'string', }, { diff --git a/packages/legacy/tools/src/models/package/package.constants.ts b/packages/legacy/tools/src/models/package/package.constants.ts index fd48e8b2ef3..dc6ba980717 100644 --- a/packages/legacy/tools/src/models/package/package.constants.ts +++ b/packages/legacy/tools/src/models/package/package.constants.ts @@ -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 = { diff --git a/packages/legacy/tools/src/models/package/package.ts b/packages/legacy/tools/src/models/package/package.ts index e8e6ad8dbbc..c336e4e0ed0 100644 --- a/packages/legacy/tools/src/models/package/package.ts +++ b/packages/legacy/tools/src/models/package/package.ts @@ -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]) @@ -104,6 +104,7 @@ class Package { ? Package.getFiles({ location: path.join(testDirectory, CONSTANTS.TEST_DIRECTORIES.UNIT), pattern: CONSTANTS.PATTERNS.TEST, + targets: config.targets, }) : Promise.resolve([]); @@ -111,6 +112,7 @@ class Package { ? Package.getFiles({ location: path.join(testDirectory, CONSTANTS.TEST_DIRECTORIES.INTEGRATION), pattern: CONSTANTS.PATTERNS.TEST, + targets: config.targets, }) : Promise.resolve([]); @@ -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> { - const target = path.join(location, pattern); + protected static getFiles({ location, pattern, targets }: + { location: string, pattern: string, targets: string | undefined }): Promise> { + let target; + if (!targets) { + target = path.join(location, pattern); + } else { + target = path.join(location, targets); + } return glob.glob(target); } diff --git a/packages/legacy/tools/test/integration/package/package.test.js b/packages/legacy/tools/test/integration/package/package.test.js index 7d46f3fc336..17da7735a13 100644 --- a/packages/legacy/tools/test/integration/package/package.test.js +++ b/packages/legacy/tools/test/integration/package/package.test.js @@ -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, }]); })); @@ -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, }]); })); @@ -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, }]); })); @@ -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, }]); })); @@ -133,6 +137,7 @@ describe('Package', () => { config = { integration: true, unit: true, + targets: 'sampleFile.ts', }; spies.Package = { @@ -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, }]); }); }); @@ -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, }]); }); }); @@ -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, }]); }); }); @@ -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, }]); }); }); @@ -306,6 +315,12 @@ describe('Package', () => { pattern: 'example/pattern', }; + const configWithTargets = { + location: 'example/location', + pattern: 'example/pattern', + targets: 'sampleTestFile.js', + }; + const results = { glob: { glob: [ @@ -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); diff --git a/packages/legacy/tools/test/integration/run-tests/run-tests.test.js b/packages/legacy/tools/test/integration/run-tests/run-tests.test.js index 70bc446bffb..16266c0b64a 100644 --- a/packages/legacy/tools/test/integration/run-tests/run-tests.test.js +++ b/packages/legacy/tools/test/integration/run-tests/run-tests.test.js @@ -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');