Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
- run: npx playwright install --with-deps
# Builds `dist/` first, so a broken build fails here and not in `npm version`
- run: npm run test-browser
# Tests the `dist/` that `test-browser` just built
- run: npm run test-dist
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ test/spec/typings/typingsSpec.js
# Playwright
test-results/
playwright-report/

# Output of `npm run test-bundler-import`
test/spec/esbuild/importSpec.build.js
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To run *Benchmark.js* performance tests, press "Run Tests" button.
3. Run test `npm run test`
- Testing **`core`** only: `npm run test-core`
- Testing **`duplex`** only: `npm run test-duplex`
- Testing the browser bundles in `dist/`: `npm run build && npm run test-dist`
4. Run test `npm run bench` (Please, consider performance when making any change)
- Testing **`core*`* only: `npm run bench-core`
- Testing **`duplex`** only: `npm run bench-duplex`
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"node_modules",
"package.json",
"playwright.config.js",
"webpack.config.js",
"tsconfig.json"
]
}
1,619 changes: 405 additions & 1,214 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@
"@playwright/test": "^1.64.0",
"benchmark": "^2.1.4",
"chalk": "^2.4.2",
"esbuild": "^0.28.2",
"event-target-shim": "^5.0.1",
"fast-deep-equal": "^2.0.1",
"http-server": "^14.1.1",
"jasmine": "^3.4.0",
"minimizer-webpack-plugin": "^5.13.0",
"typescript": "~3.5.2",
"webpack": "^5.111.1",
"webpack-cli": "^7.2.3"
"typescript": "~3.5.2"
},
"scripts": {
"tsc": "npm run tsc-common && npm run tsc-module",
"tsc-common": "tsc",
"tsc-module": "tsc --module esnext --moduleResolution node --outDir \"module/\" && npm run tsc-to-mjs",
"tsc-to-mjs": "bash tsc-to-mjs.sh",
"version": "npm run build && git add commonjs module dist",
"build": "npm run tsc && webpack",
"version": "npm run build && npm run test-dist && git add commonjs module dist",
"build": "npm run tsc && npm run build-dist",
"build-dist": "npm run bundle -- --outfile=dist/fast-json-patch.js && npm run bundle -- --minify --outfile=dist/fast-json-patch.min.js",
"bundle": "esbuild index.js --bundle --format=iife --global-name=jsonpatch --target=es5 --legal-comments=inline --banner:js=\"/*! fast-json-patch, version: $npm_package_version */\"",
"serve": "http-server -p 5000 --silent",
"tsc-watch": "tsc -w",
"test": "npm run tsc && npm run test-core && npm run test-duplex && npm run test-commonjs && npm run test-webpack-import && npm run test-typings",
"test": "npm run tsc && npm run test-core && npm run test-duplex && npm run test-commonjs && npm run test-bundler-import && npm run test-typings",
"test-commonjs": "jasmine test/spec/commonjs/requireSpec.js",
"test-webpack-import": "webpack --env NODE_ENV=test && jasmine test/spec/webpack/importSpec.build.js",
"test-bundler-import": "esbuild test/spec/esbuild/importSpec.src.js --bundle --platform=node --main-fields=module,main --outfile=test/spec/esbuild/importSpec.build.js && jasmine test/spec/esbuild/importSpec.build.js",
"test-typings": "tsc -p test/spec/typings",
"test-duplex": "node --experimental-modules jasmine-run.mjs test/**/*[sS]pec.mjs",
"test-core": "node --experimental-modules jasmine-run.mjs 'test/spec/{jsonPatchTestsSpec,coreSpec,validateSpec}.mjs'",
"test-browser": "npm run build && playwright test",
"test-dist": "jasmine test/spec/dist/distSpec.js",
"bench": "npm run bench-core && npm run bench-duplex",
"bench-core": "node test/spec/coreBenchmark.js",
"bench-duplex": "node test/spec/coreBenchmark.js && node test/spec/duplexBenchmark.js"
Expand Down
47 changes: 47 additions & 0 deletions test/spec/dist/distSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Smoke test for the browser bundles in `dist/`, loaded the way a `<script>`
* tag loads them. Run it after `npm run build`. The browser suite imports
* `index.mjs`, so it never loads the bundles themselves.
*/
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const { version } = require('../../../package.json');
const api = require('../../../index.js');

const DIST_DIR = path.resolve(__dirname, '../../../dist');
const BUNDLES = ['fast-json-patch.js', 'fast-json-patch.min.js'];

describe('Browser bundles in dist/', function () {
BUNDLES.forEach(function (file) {
describe(file, function () {
const source = fs.readFileSync(path.join(DIST_DIR, file), 'utf8');

it('should keep the version banner', function () {
expect(source).toContain('fast-json-patch, version: ' + version);
});

it('should define the `jsonpatch` global with the API of `index.js`', function () {
const jsonpatch = loadAsScript(source);
expect(Object.keys(jsonpatch).sort()).toEqual(Object.keys(api).sort());
});

it('should apply and generate patches', function () {
const jsonpatch = loadAsScript(source);
const doc = { list: [1, 2] };
jsonpatch.applyPatch(doc, [{ op: 'add', path: '/list/-', value: 3 }]);
expect(doc).toEqual({ list: [1, 2, 3] });
// The patch is built in the bundle's own realm, so compare it as JSON
expect(JSON.stringify(jsonpatch.compare({ a: 1 }, { a: 2 })))
.toBe('[{"op":"replace","path":"/a","value":2}]');
});
});
});
});

// Runs the bundle in a fresh global scope, as a `<script>` tag would
function loadAsScript(source) {
const context = vm.createContext({});
vm.runInContext(source, context);
return context.jsonpatch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import jsonpatch from '../../..'; //as used in https://github.com/swagger-api/sw
import * as jsonpatchStar from '../../..';
import { applyOperation } from '../../..';

describe('This package imported by Webpack', function () {
describe('This package imported by a bundler (esbuild)', function () {
describe('import default', function () {
it('should have the expected structure', function () {
verifyObjectStructure(jsonpatch);
Expand Down
2 changes: 1 addition & 1 deletion test/spec/typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
/* don't auto-include transitive @types (e.g. @types/node from webpack) */
/* don't auto-include transitive @types (e.g. @types/node) */
"types": []
},
"files": [
Expand Down
13 changes: 0 additions & 13 deletions test/spec/webpack/importSpec.build.js

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* emitting `use strict` made PuppetJS break */
"allowSyntheticDefaultImports": true,
"noImplicitUseStrict": true,
/* don't auto-include transitive @types (e.g. @types/node from webpack) */
/* don't auto-include transitive @types (e.g. @types/node) */
"types": []
},
"include": [
Expand Down
Loading
Loading