-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- as CommonJS (require) - as import in Webpack - as import in TypeScript with typings code is backported from 3.x alpha (cec3d27)
- Loading branch information
Showing
8 changed files
with
167 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ npm-debug.log | |
|
||
# Typescript | ||
*.d.ts | ||
test/spec/typings/typingsSpec.js | ||
|
||
# compiled files | ||
src/*.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).withContext("result from require() should be an object").toEqual("object"); | ||
expect(typeof jsonpatch).withContext("result from require() should not be a function").not.toEqual("function"); | ||
expect(jsonpatch.applyOperation).withContext("applyOperation should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.applyPatch).withContext("applyPatch should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.applyReducer).withContext("applyReducer should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.getValueByPointer).withContext("getValueByPointer should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.validate).withContext("validate should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.validator).withContext("validator should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.JsonPatchError).withContext("JsonPatchError should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.deepClone).withContext("deepClone should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.escapePathComponent).withContext("escapePathComponent should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.unescapePathComponent).withContext("unescapePathComponent should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.unobserve).withContext("unobserve should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.observe).withContext("observe should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.generate).withContext("generate should be a method within the object").toBeDefined(); | ||
expect(jsonpatch.compare).withContext("compare should be a method within the object").toBeDefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.