diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-07-28 02:51:30 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-07-28 02:51:30 +0800 |
commit | c851c3763060ca4cf9e37d75e36e534f9b7d9294 (patch) | |
tree | 82bb74e4521804377869c099cf5eba019f06d4d5 /packages/monorepo-scripts/src/test_installation.ts | |
parent | a0d7b1efa59cf7322a97ef75268c372068592976 (diff) | |
parent | 44d1be27e626c4e80ccf80d3f070a890c45f02ac (diff) | |
download | dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar.gz dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar.bz2 dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar.lz dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar.xz dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.tar.zst dexon-sol-tools-c851c3763060ca4cf9e37d75e36e534f9b7d9294.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/website/upgrade-allowance-toggles-to-locks-and-checks
Diffstat (limited to 'packages/monorepo-scripts/src/test_installation.ts')
-rw-r--r-- | packages/monorepo-scripts/src/test_installation.ts | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 668d4ef1d..a8ddf0c58 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -8,26 +8,42 @@ import * as rimraf from 'rimraf'; import { utils } from './utils/utils'; +// Packages might not be runnable if they are command-line tools or only run in browsers. +const UNRUNNABLE_PACKAGES = [ + '@0xproject/abi-gen', + '@0xproject/sra-report', + '@0xproject/react-shared', + '@0xproject/react-docs', +]; + (async () => { + const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; + const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); - const packages = utils.getPackages(monorepoRootPath); + const packages = utils.getTopologicallySortedPackages(monorepoRootPath); const installablePackages = _.filter( packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); + utils.log('Testing packages:'); + _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); for (const installablePackage of installablePackages) { - const packagePath = installablePackage.location; + const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); + const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version; const packageName = installablePackage.packageJson.name; - utils.log(`Testing ${packageName}`); - let result = await execAsync('npm pack', { cwd: packagePath }); - const packedPackageFileName = result.stdout.trim(); + utils.log(`Testing ${packageName}@${lastChangelogVersion}`); const testDirectory = path.join(monorepoRootPath, '../test-env'); + rimraf.sync(testDirectory); fs.mkdirSync(testDirectory); - result = await execAsync('yarn init --yes', { cwd: testDirectory }); - utils.log(`Installing ${packedPackageFileName}`); - result = await execAsync(`yarn add ${packagePath}/${packedPackageFileName}`, { cwd: testDirectory }); + await execAsync('yarn init --yes', { cwd: testDirectory }); + const npmrcFilePath = path.join(testDirectory, '.npmrc'); + fs.writeFileSync(npmrcFilePath, `registry=${registry}`); + utils.log(`Installing ${packageName}@${lastChangelogVersion}`); + await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=${registry}`, { + cwd: testDirectory, + }); const indexFilePath = path.join(testDirectory, 'index.ts'); - fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\n`); + fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\nconsole.log(Package);\n`); const tsConfig = { compilerOptions: { typeRoots: ['node_modules/@0xproject/typescript-typings/types', 'node_modules/@types'], @@ -47,6 +63,13 @@ import { utils } from './utils/utils'; const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); await execAsync(tscBinaryPath, { cwd: testDirectory }); utils.log(`Successfully compiled with ${packageName} as a dependency`); + const isUnrunnablePkg = _.includes(UNRUNNABLE_PACKAGES, packageName); + if (!isUnrunnablePkg) { + const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); + utils.log(`Running test script with ${packageName} imported`); + await execAsync(`node ${transpiledIndexFilePath}`); + utils.log(`Successfilly ran test script with ${packageName} imported`); + } rimraf.sync(testDirectory); } })().catch(err => { |