Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Mar 13, 2024
2 parents 3ff97af + cbe1c4b commit f61dd22
Show file tree
Hide file tree
Showing 10 changed files with 2,588 additions and 522 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
branches: [$default-branch]
schedule:
- cron: '0 12 * * 0'

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'npm'

- name: Install
run: npm ci

- name: Run lint tests
run: npm run test-lint

browser-tests:
name: Browser Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'npm'

- name: Install
run: npm ci

- name: Run browser tests
run: npm run test-browser

tests:
name: Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [10, 12]
os: [ubuntu-latest, windows-latest]
include:
- coverage: true
node-version: 16
os: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install
run: npm ci

- name: Run system tests
run: npm run test-system

- name: Run unit tests
run: npm run test-unit

- if: ${{ matrix.coverage }}
name: Upload coverage
run: npm run codecov -- -c -Z -f .coverage/coverage-final.json -F unit

- name: Run integration tests
run: npm run test-integration
97 changes: 0 additions & 97 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.2.0:
date: 2024-03-13
new features:
- GH-640 Added option to allow blocking globals in specific executions
chores:
- Updated dependencies

2.1.0:
date: 2024-02-28
new features:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Uniscope [![Build Status](https://travis-ci.com/postmanlabs/uniscope.svg?branch=develop)](https://travis-ci.com/postmanlabs/uniscope) [![codecov](https://codecov.io/gh/postmanlabs/uniscope/branch/develop/graph/badge.svg)](https://codecov.io/gh/postmanlabs/uniscope)
# Uniscope [![CI](https://github.com/postmanlabs/uniscope/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/postmanlabs/uniscope/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/postmanlabs/uniscope/branch/develop/graph/badge.svg)](https://codecov.io/gh/postmanlabs/uniscope)

The goal of this module is to provide a uniform execution environment to a JavaScript code between browser and NodeJS.<br/>
For example, global functions and objects in NodeJS such as `setImmediate` and `global` are not easily available to the script. And on the other hand, browser-specific global properties such as `requestAnimationFrame` and `window` is not available as well.
Expand Down Expand Up @@ -53,8 +53,8 @@ An asynchronous script will require an explicit call of a global function `__exi
```javascript
myscope.set('setTimeout', global.setTimeout); // inject setTimeout

// note the 2nd parameter is set to `true` for async
myscope.exec('setTimeout(function () { __exitscope(null); }, 1000)', true, function (err) {
// note the 2nd parameter is set to `{ async: true }`
myscope.exec('setTimeout(function () { __exitscope(null); }, 1000)', { async: true }, function (err) {
err ? console.error(err.stack || err) : console.log('execution complete');
});
```
Expand Down
20 changes: 14 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,25 @@ class Uniscope {
* Executes a string within a protected Uniscope of controlled set of globals.
*
* @param {String} code A string representing a JavaScript expression, statement, or sequence of statements
* @param {Boolean} [async=false] When set to true, callback will be called when `__exitscope` is triggered
* @param {Object} [options] An object of options for the exec
* @param {Boolean} [options.async=false] When set to true, callback will be called when `__exitscope` is triggered
* @param {String[]} [options.block] Specify a set of global variables that will not be allowed to trickle in
* @param {Function} callback Callback function to be called at the end of execution
*/
exec (code, async, callback) {
exec (code, options, callback) {
// allow polymorphic parameter to enable async functions
// and validate the primary code parameter
if (async && !callback) {
callback = async;
async = false;
if (options && !callback) {
callback = options;
options = {};
}

if (typeof options === 'boolean') {
options = { async: options };
}

const async = Boolean(options && options.async);

if (!util.isFunction(callback)) { throw new Error(ERROR_CALLBACK_MISSING); }
if (!util.isString(code)) { return callback(new TypeError(ERROR_CODE_MUST_BE_STRING)); }

Expand Down Expand Up @@ -233,7 +241,7 @@ class Uniscope {
});

// based on Uniscope configuration, the globals that we block are specifically set to undefined
util.forEach(blocked, (key) => {
util.forEach(blocked.concat(options.block || []), (key) => {
let position = globals.indexOf(key);

(position === -1) && (position = globals.length);
Expand Down
4 changes: 0 additions & 4 deletions npm/test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ const path = require('path'),
KARMA_CONFIG_PATH = path.join(__dirname, '..', 'test', 'karma.conf');

module.exports = function (exit) {
if (process.env.TRAVIS_OS_NAME === 'windows') { // eslint-disable-line no-process-env
return console.info(chalk.yellow.bold('Skipping browser tests on windows...'));
}

console.info(chalk.yellow.bold('Running unit tests within browser...'));

(new KarmaServer({ // eslint-disable no-new
Expand Down
Loading

0 comments on commit f61dd22

Please sign in to comment.