forked from facebook/lexical
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test that builds the examples with release artifacts
- Loading branch information
Showing
13 changed files
with
254 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
// @ts-check | ||
'use strict'; | ||
|
||
const fs = require('fs-extra'); | ||
const glob = require('glob'); | ||
const {packagesManager} = require('../../shared/packagesManager'); | ||
const path = require('node:path'); | ||
const {describeExample} = require('./utils'); | ||
|
||
describe('prepare-release tests', () => { | ||
for (const pkg of packagesManager.getPublicPackages()) { | ||
describe(pkg.getNpmName(), () => { | ||
const tgzPath = path.join( | ||
'npm', | ||
`${pkg.getDirectoryName()}-${pkg.packageJson.version}.tgz`, | ||
); | ||
test(`${tgzPath} exists`, () => | ||
expect(fs.existsSync(tgzPath)).toBe(true)); | ||
}); | ||
} | ||
test('builds', async () => {}); | ||
}); | ||
glob | ||
.sync('examples/*/package.json') | ||
.forEach((exampleJsonPath) => describeExample(exampleJsonPath, () => {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
// @ts-check | ||
'use strict'; | ||
|
||
const path = require('node:path'); | ||
const fs = require('fs-extra'); | ||
const {exec} = require('child-process-promise'); | ||
const {packagesManager} = require('../../shared/packagesManager'); | ||
const {version} = require('../../shared/readMonorepoPackageJson')(); | ||
|
||
/** | ||
* @param {import('@jest/types').Config.GlobalConfig} globalConfig | ||
* @param {import('@jest/types').Config.ProjectConfig} projectConfig | ||
*/ | ||
module.exports = async function (globalConfig, projectConfig) { | ||
const needsBuild = packagesManager | ||
.getPublicPackages() | ||
.some( | ||
(pkg) => | ||
!fs.existsSync( | ||
path.resolve(`./npm/${pkg.getDirectoryName()}-${version}.tgz`), | ||
), | ||
); | ||
if (!needsBuild) { | ||
return; | ||
} | ||
await exec('npm run prepare-release'); | ||
const packDest = path.resolve('./npm'); | ||
fs.mkdirpSync(packDest); | ||
for (const pkg of packagesManager.getPublicPackages()) { | ||
const cwd = process.cwd(); | ||
try { | ||
process.chdir(pkg.resolve('npm')); | ||
await exec(`npm pack --pack-destination '${packDest}'`); | ||
} finally { | ||
process.chdir(cwd); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
// @ts-check | ||
'use strict'; | ||
|
||
const {exec} = require('child-process-promise'); | ||
const {packagesManager} = require('../../shared/packagesManager'); | ||
const fs = require('fs-extra'); | ||
const path = require('node:path'); | ||
|
||
const LONG_TIMEOUT = 60 * 1000; | ||
|
||
/** | ||
* exec the command in a child process from the given directory. | ||
* | ||
* @param {string} dir | ||
* @param {Parameters<typeof exec>} args | ||
* @returns {Promise<string>} | ||
*/ | ||
async function dirExec(dir, ...args) { | ||
const cwd = process.cwd(); | ||
try { | ||
process.chdir(dir); | ||
return await exec(...args); | ||
} finally { | ||
process.chdir(cwd); | ||
} | ||
} | ||
|
||
exports.dirExec = dirExec; | ||
|
||
/** | ||
* @typedef {Object} ExampleContext | ||
* @property {string} packageJsonPath | ||
* @property {string} exampleDir | ||
* @property {Record<string, any>} packageJson | ||
*/ | ||
|
||
/** @param {ctx} ExampleContext */ | ||
async function buildExample({packageJson, exampleDir}) { | ||
const lexicalPackages = new Map( | ||
packagesManager.getPublicPackages().map((pkg) => [pkg.getNpmName(), pkg]), | ||
); | ||
const installDeps = [ | ||
'dependencies', | ||
'devDependencies', | ||
'peerDependencies', | ||
].flatMap((depType) => { | ||
const deps = packageJson[depType] || {}; | ||
return Object.keys(deps).flatMap((k) => { | ||
const pkg = lexicalPackages.get(k); | ||
return pkg | ||
? [ | ||
path.resolve( | ||
'npm', | ||
`${pkg.getDirectoryName()}-${pkg.packageJson.version}.tgz`, | ||
), | ||
] | ||
: []; | ||
}); | ||
}); | ||
if (installDeps.length === 0) { | ||
throw new Error(`No lexical dependencies detected: ${exampleDir}`); | ||
} | ||
['node_modules', 'dist', 'build'].forEach((cleanDir) => | ||
fs.removeSync(path.resolve(exampleDir, cleanDir)), | ||
); | ||
await dirExec( | ||
exampleDir, | ||
`npm install --no-save --no-package-lock ${installDeps | ||
.map((fn) => `'${fn}'`) | ||
.join(' ')}`, | ||
); | ||
await dirExec(exampleDir, `npm run build`); | ||
} | ||
|
||
/** | ||
* Build the example project with prerelease lexical artifacts | ||
* | ||
* @param {string} packgeJsonPath | ||
* @param {(ctx: ExampleContext) => void} bodyFun | ||
*/ | ||
function describeExample(packageJsonPath, bodyFun) { | ||
const packageJson = fs.readJsonSync(packageJsonPath); | ||
const exampleDir = path.dirname(packageJsonPath); | ||
/** @type {ExampleContext} */ | ||
const ctx = {exampleDir, packageJson, packageJsonPath}; | ||
describe(exampleDir, () => { | ||
beforeAll(async () => buildExample(ctx), LONG_TIMEOUT); | ||
test('install & build succeeded', () => { | ||
expect(true).toBe(true); | ||
}); | ||
test('installed lexical', () => { | ||
expect( | ||
fs.existsSync(path.join(exampleDir, 'node_modules', 'lexical')), | ||
).toBe(true); | ||
}); | ||
if (packageJson.scripts.test) { | ||
test( | ||
'tests pass', | ||
async () => { | ||
expect(await dirExec(exampleDir, 'npm run build')).not.toBe(null); | ||
}, | ||
LONG_TIMEOUT, | ||
); | ||
} | ||
bodyFun(ctx); | ||
}); | ||
} | ||
|
||
exports.describeExample = describeExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters