Skip to content

Commit ca78a5b

Browse files
JamesHenrybenlesh
authored andcommitted
chore: allow integration tests to work with local @rxjs/observable
1 parent 0589412 commit ca78a5b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/rxjs/integration/import/fixtures

packages/rxjs/integration/import/fixtures/browser/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>RxJS Import Integration Test</title>
77
</head>
8+
<script type="importmap">
9+
{
10+
"imports": {
11+
"@rxjs/observable": "./node_modules/@rxjs/observable/dist/browser/index.js"
12+
}
13+
}
14+
</script>
815
<body>
916
<script type="module" src="./browser-test.js"></script>
1017
</body>

packages/rxjs/integration/import/runner.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const path = require('path');
2+
const fs = require('fs');
23
const { spawn } = require('child_process');
34
const projectRoot = process.cwd();
45
const rxjsRoot = path.join(__dirname, '../../');
6+
const rxjsObservableRoot = path.join(__dirname, '../../../observable');
57
const fixturesDirectory = path.join(__dirname, 'fixtures');
68
const rxjsVersion = require(path.join(rxjsRoot, 'package.json')).version;
79
const tgzPath = path.join(rxjsRoot, `rxjs-${rxjsVersion}.tgz`);
10+
const rxjsObservableTgzPath = path.join(rxjsObservableRoot, `rxjs-observable-${rxjsVersion}.tgz`);
811

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

5861
async function main() {
5962
try {
63+
console.log('Building and packaging @rxjs/observable...');
64+
try {
65+
await execAsync('yarn build && npm pack', rxjsObservableRoot);
66+
} catch (err) {
67+
console.error('❌ Failed to build and package @rxjs/observable!');
68+
console.error(err);
69+
throw err;
70+
}
6071
console.log('Building and packaging RxJS...');
6172
try {
6273
await execAsync('yarn build && npm pack', rxjsRoot);
@@ -76,6 +87,10 @@ async function main() {
7687
try {
7788
console.log('\n');
7889
console.log(`Running ${fixtureName}...`);
90+
91+
console.log('Setting custom dependency resolution for local @rxjs/observable...');
92+
addYarnResolution(fixturePath, '@rxjs/observable', `file:${path.relative(fixturePath, rxjsObservableTgzPath)}`);
93+
7994
await execAsync(`yarn install && yarn add ${tgzPath}`, fixturePath);
8095
await execAsync('yarn test', fixturePath);
8196
console.log(`✅ ${fixtureName} import test passed!`);
@@ -89,6 +104,7 @@ async function main() {
89104
try {
90105
await execAsync('yarn remove rxjs', fixturePath);
91106
await execAsync('rm -rf ./node_modules ./package-lock.json ./yarn.lock', fixturePath);
107+
removeYarnResolution(fixturePath, '@rxjs/observable');
92108
} catch (err) {
93109
console.warn('fixtured not cleaned up', err);
94110
}
@@ -101,7 +117,26 @@ async function main() {
101117
}
102118
} finally {
103119
await execAsync(`rm ${tgzPath}`, projectRoot);
120+
await execAsync(`rm ${rxjsObservableTgzPath}`, rxjsObservableRoot);
104121
}
105122
}
106123

107124
main();
125+
126+
function addYarnResolution(fixturePath, name, version) {
127+
const fixturePackageJson = fs.readFileSync(path.join(fixturePath, 'package.json'));
128+
const fixturePackageJsonObj = JSON.parse(fixturePackageJson);
129+
fixturePackageJsonObj.resolutions = fixturePackageJsonObj.resolutions || {};
130+
fixturePackageJsonObj.resolutions[name] = version;
131+
fs.writeFileSync(path.join(fixturePath, 'package.json'), JSON.stringify(fixturePackageJsonObj, null, 2));
132+
}
133+
134+
function removeYarnResolution(fixturePath, name) {
135+
const fixturePackageJson = fs.readFileSync(path.join(fixturePath, 'package.json'));
136+
const fixturePackageJsonObj = JSON.parse(fixturePackageJson);
137+
delete fixturePackageJsonObj.resolutions[name];
138+
if (!Object.keys(fixturePackageJsonObj.resolutions).length) {
139+
delete fixturePackageJsonObj.resolutions;
140+
}
141+
fs.writeFileSync(path.join(fixturePath, 'package.json'), JSON.stringify(fixturePackageJsonObj, null, 2) + '\n');
142+
}

0 commit comments

Comments
 (0)