Skip to content

Commit

Permalink
test: update import integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calebboyd committed Feb 23, 2021
1 parent 912c265 commit 6487900
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions integration/import/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { strict as assert } from 'assert'
import { readFileSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import * as rx from 'rxjs'
import * as operators from 'rxjs/operators'

const readJSONSync = (path) => JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), path), 'utf-8'))
const rxSnapshot = readJSONSync('rx.json');
const operatorsSnapshot = readJSONSync('operators.json');

assert.ok(rx, 'main export should exists');
assert.ok(operators, 'operator export should exists');

assert.deepStrictEqual(Object.keys(rx).sort(), rxSnapshot.sort(), 'main export should include exports');
assert.deepStrictEqual(Object.keys(operators).sort(), operatorsSnapshot.sort(), 'operator export should include exports');
8 changes: 0 additions & 8 deletions integration/import/fixtures/commonjs/package.json

This file was deleted.

11 changes: 11 additions & 0 deletions integration/import/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "rxjs-import-test",
"version": "0.0.1",
"main": "./index.js",
"type": "commonjs",
"scripts": {
"test": "npm run test:commonjs && npm run test:esm",
"test:commonjs": "node ./common.cjs",
"test:esm": "node ./esm.mjs"
}
}
41 changes: 14 additions & 27 deletions integration/import/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { exec, rm } from 'shelljs';
import { promisify } from 'util';
import * as fs from 'fs';

import * as rx_export_src from '../../src/index.js';
import * as operators_export_src from '../../src/operators/index.js';
import * as rx_export_src from 'rxjs';
import * as operators_export_src from 'rxjs/operators';

const writeFileAsync = promisify(fs.writeFile);
const projectRoot = process.cwd();
const { version } = require(path.join(projectRoot, 'package.json'));
const { version } = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf-8'));

const execPromise = (cmd: string, cwd = projectRoot) =>
new Promise((resolve, reject) =>
Expand All @@ -34,37 +34,24 @@ const execPromise = (cmd: string, cwd = projectRoot) =>
}
}));

enum IMPORT_TYPE {
COMMONJS = 'commonjs'
}

const prepareFixture = async (pkgPath: string, fixturePath: string) => {
rm('-rf', path.join(fixturePath, 'node_modules'));
rm('-rf', path.join(fixturePath, 'rx.json'));
rm('-rf', path.join(fixturePath, 'operators.json'));

// create snapShot from existing src's export site
writeFileAsync(path.join(fixturePath, 'rx.json'), JSON.stringify(Object.keys(rx_export_src)));
writeFileAsync(path.join(fixturePath, 'operators.json'), JSON.stringify(Object.keys(operators_export_src)));

await execPromise(`npm install ${pkgPath} --no-save`, fixturePath);
};

const main = async () => {
// create local pkgs
await execPromise('npm run build:package');
await execPromise('npm pack');

const pkgPath = path.join(projectRoot, `rxjs-${version}.tgz`);

// install local pkg to each fixture path, run test scripts
for (const key in IMPORT_TYPE) {
const value = (IMPORT_TYPE as any)[key];
const fixturePath = path.join(__dirname, 'fixtures', value);

await prepareFixture(pkgPath, fixturePath);
await execPromise('npm test', fixturePath);
}

rm('-rf', path.join(__dirname, 'node_modules'));
rm('-rf', path.join(__dirname, 'rx.json'));
rm('-rf', path.join(__dirname, 'operators.json'));

// create snapShot from existing src's export site
writeFileAsync(path.join(__dirname, 'rx.json'), JSON.stringify(Object.keys(rx_export_src)));
writeFileAsync(path.join(__dirname, 'operators.json'), JSON.stringify(Object.keys(operators_export_src)));

await execPromise(`npm install ${pkgPath} --no-save`, __dirname);
await execPromise('npm test', __dirname);
};

main().catch((err) => {
Expand Down

0 comments on commit 6487900

Please sign in to comment.