Skip to content

Commit

Permalink
add external API tests to v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
warpech committed Aug 9, 2019
1 parent 476caa8 commit 5bb0fd5
Show file tree
Hide file tree
Showing 9 changed files with 1,146 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ npm-debug.log

# Typescript
*.d.ts
test/spec/typings/typingsSpec.js

# compiled files
src/*.js
Expand Down
10 changes: 7 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
"version": "tsc && webpack && git add -A",
"build": "tsc && webpack",
"tsc-watch": "tsc -w",
"test": "npm run tsc && npm run test-core && npm run test-duplex",
"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-sauce": "npm run build && node test/Sauce/Runner.js",
"test-commonjs": "jasmine test/spec/commonjs/requireSpec.js",
"test-webpack-import": "webpack --env.NODE_ENV=test && jasmine test/spec/webpack/importSpec.build.js",
"test-typings": "tsc test/spec/typings/typingsSpec.ts",
"test-duplex": "jasmine DUPLEX=yes JASMINE_CONFIG_PATH=test/jasmine.json",
"test-core": "jasmine DUPLEX=no JASMINE_CONFIG_PATH=test/jasmine.json test/spec/jsonPatchTestsSpec.js test/spec/coreSpec.js test/spec/validateSpec.js",
"bench": "npm run bench-core && npm run bench-duplex",
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"spec_dir": "test",
"spec_files": [
"**/*[sS]pec.js"
"spec/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
Expand Down
24 changes: 24 additions & 0 deletions test/spec/commonjs/requireSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const jsonpatch = require('../../..');

describe('CommonJS', function () {
describe('require', function () {
it('should have the expected structure', function () {
expect(typeof jsonpatch).toEqual("object");
expect(typeof jsonpatch).not.toEqual("function");
expect(jsonpatch.applyOperation).toBeDefined();
expect(jsonpatch.applyPatch).toBeDefined();
expect(jsonpatch.applyReducer).toBeDefined();
expect(jsonpatch.getValueByPointer).toBeDefined();
expect(jsonpatch.validate).toBeDefined();
expect(jsonpatch.validator).toBeDefined();
expect(jsonpatch.JsonPatchError).toBeDefined();
expect(jsonpatch.deepClone).toBeDefined();
expect(jsonpatch.escapePathComponent).toBeDefined();
expect(jsonpatch.unescapePathComponent).toBeDefined();
expect(jsonpatch.unobserve).toBeDefined();
expect(jsonpatch.observe).toBeDefined();
expect(jsonpatch.generate).toBeDefined();
expect(jsonpatch.compare).toBeDefined();
});
});
});
22 changes: 22 additions & 0 deletions test/spec/typings/typingsSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Run using `npm run test-typings`
* The sole fact that this file compiles means that typings work
* This follows how DefinitelyTyped tests work
* @see https://stackoverflow.com/questions/49296151/how-to-write-tests-for-typescript-typing-definition
*/

// import jsonpatch from '../../..';
import * as jsonpatchStar from '../../..';
import { applyPatch, Operation } from '../../..';

const document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };

const typedPatch = new Array<Operation>({ op: "replace", path: "/firstName", value: "Joachim" });
const untypedPatch = [{ op: "replace", path: "/firstName", value: "Joachim" }];

// const test_jsonpatch = jsonpatch.applyPatch(document, typedPatch).newDocument;
const test_jsonpatchStar = jsonpatchStar.applyPatch(document, typedPatch).newDocument;
const test_applyPatch = applyPatch(document, typedPatch).newDocument;

// the below line would NOT compile with TSC
// const test_applyPatch = applyPatch(document, untypedPatch).newDocument;

0 comments on commit 5bb0fd5

Please sign in to comment.