build: add npm package manifest to npm_integration_test (#35669)

PR Close #35669
This commit is contained in:
Greg Magolan
2020-02-25 11:40:45 -08:00
committed by Miško Hevery
parent f9f44bf743
commit 1f3dd000ad
3 changed files with 61 additions and 5 deletions

View File

@ -140,6 +140,7 @@ class TestRunner {
this.config = config;
this.successful = 0;
this._setupTestFiles();
this._writeNpmPackageManifest();
}
/**
@ -297,6 +298,27 @@ class TestRunner {
log(`test files from '${rootDirectory(this.config.testFiles)}' copied to tmp folder ${this.testRoot}`);
}
}
/**
* @internal
*
* Write an NPM_PACKAGE_MANIFEST.json file to the test root with a mapping of
* the npm package mappings for this this test. Integration tests can opt
* to use this mappings file instead of the built-in `patch-package-json`
* command.
*/
_writeNpmPackageManifest() {
if (!this.testRoot) {
fail(`test files not yet setup`);
}
const manifest = {};
for (const key of Object.keys(this.config.npmPackages)) {
manifest[key] = runfiles.resolveWorkspaceRelative(this.config.npmPackages[key]);
}
const manifestPath = `${this.testRoot}/NPM_PACKAGE_MANIFEST.json`;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
log(`npm package manifest written to ${manifestPath}`);
}
}
const config = require(process.argv[2]);