Skip to content

Commit

Permalink
chore: allow integration tests to work with local @rxjs/observable
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and benlesh committed Feb 29, 2024
1 parent 0589412 commit ca78a5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/rxjs/integration/import/fixtures
7 changes: 7 additions & 0 deletions packages/rxjs/integration/import/fixtures/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RxJS Import Integration Test</title>
</head>
<script type="importmap">
{
"imports": {
"@rxjs/observable": "./node_modules/@rxjs/observable/dist/browser/index.js"
}
}
</script>
<body>
<script type="module" src="./browser-test.js"></script>
</body>
Expand Down
35 changes: 35 additions & 0 deletions packages/rxjs/integration/import/runner.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const path = require('path');
const fs = require('fs');
const { spawn } = require('child_process');
const projectRoot = process.cwd();
const rxjsRoot = path.join(__dirname, '../../');
const rxjsObservableRoot = path.join(__dirname, '../../../observable');
const fixturesDirectory = path.join(__dirname, 'fixtures');
const rxjsVersion = require(path.join(rxjsRoot, 'package.json')).version;
const tgzPath = path.join(rxjsRoot, `rxjs-${rxjsVersion}.tgz`);
const rxjsObservableTgzPath = path.join(rxjsObservableRoot, `rxjs-observable-${rxjsVersion}.tgz`);

// These are the fixtures to run the import test against
// they map to directories in the fixtures directory
Expand Down Expand Up @@ -57,6 +60,14 @@ function execAsync(cmd, cwd = '.') {

async function main() {
try {
console.log('Building and packaging @rxjs/observable...');
try {
await execAsync('yarn build && npm pack', rxjsObservableRoot);
} catch (err) {
console.error('❌ Failed to build and package @rxjs/observable!');
console.error(err);
throw err;
}
console.log('Building and packaging RxJS...');
try {
await execAsync('yarn build && npm pack', rxjsRoot);
Expand All @@ -76,6 +87,10 @@ async function main() {
try {
console.log('\n');
console.log(`Running ${fixtureName}...`);

console.log('Setting custom dependency resolution for local @rxjs/observable...');
addYarnResolution(fixturePath, '@rxjs/observable', `file:${path.relative(fixturePath, rxjsObservableTgzPath)}`);

await execAsync(`yarn install && yarn add ${tgzPath}`, fixturePath);
await execAsync('yarn test', fixturePath);
console.log(`✅ ${fixtureName} import test passed!`);
Expand All @@ -89,6 +104,7 @@ async function main() {
try {
await execAsync('yarn remove rxjs', fixturePath);
await execAsync('rm -rf ./node_modules ./package-lock.json ./yarn.lock', fixturePath);
removeYarnResolution(fixturePath, '@rxjs/observable');
} catch (err) {
console.warn('fixtured not cleaned up', err);
}
Expand All @@ -101,7 +117,26 @@ async function main() {
}
} finally {
await execAsync(`rm ${tgzPath}`, projectRoot);
await execAsync(`rm ${rxjsObservableTgzPath}`, rxjsObservableRoot);
}
}

main();

function addYarnResolution(fixturePath, name, version) {
const fixturePackageJson = fs.readFileSync(path.join(fixturePath, 'package.json'));
const fixturePackageJsonObj = JSON.parse(fixturePackageJson);
fixturePackageJsonObj.resolutions = fixturePackageJsonObj.resolutions || {};
fixturePackageJsonObj.resolutions[name] = version;
fs.writeFileSync(path.join(fixturePath, 'package.json'), JSON.stringify(fixturePackageJsonObj, null, 2));
}

function removeYarnResolution(fixturePath, name) {
const fixturePackageJson = fs.readFileSync(path.join(fixturePath, 'package.json'));
const fixturePackageJsonObj = JSON.parse(fixturePackageJson);
delete fixturePackageJsonObj.resolutions[name];
if (!Object.keys(fixturePackageJsonObj.resolutions).length) {
delete fixturePackageJsonObj.resolutions;
}
fs.writeFileSync(path.join(fixturePath, 'package.json'), JSON.stringify(fixturePackageJsonObj, null, 2) + '\n');
}

0 comments on commit ca78a5b

Please sign in to comment.