Skip to content

Commit

Permalink
Switch to pure CommonJS
Browse files Browse the repository at this point in the history
Now that we have dependencies, anything else is just fiddly.
  • Loading branch information
domenic committed Sep 27, 2016
1 parent fc9f868 commit bb51e07
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 531 deletions.
26 changes: 3 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,9 @@ chai.should();

You can of course put this code in a common test fixture file; for an example using [Mocha][], see [the Chai as Promised tests themselves][fixturedemo].

### AMD
### In the Browser

Chai as Promised supports being used as an [AMD][amd] module, registering itself anonymously (just like Chai). So, assuming you have configured your loader to map the Chai and Chai as Promised files to the respective module IDs `"chai"` and `"chai-as-promised"`, you can use them as follows:

```javascript
define(function (require, exports, module) {
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");

chai.use(chaiAsPromised);

// and Chai setup code as above
});
```

### `<script>` tag

If you include Chai as Promised directly with a `<script>` tag, after the one for Chai itself, then it will automatically plug in to Chai and be ready for use:

```html
<script src="chai.js"></script>
<script src="chai-as-promised.js"></script>
<!-- and Chai setup code as above -->
```
To use Chai as Promised in environments that don't support Node.js-like CommonJS modules, you'll need to use a bundling tool like [browserify][].

### Karma

Expand All @@ -265,3 +244,4 @@ Chai as Promised is only compatible with modern browsers (IE ≥9, Safari ≥6,
[sinon-chai]: https://github.com/domenic/sinon-chai
[Karma]: https://karma-runner.github.io/
[karma-chai-as-promised]: https://github.com/vlkosinov/karma-chai-as-promised
[browserify]: http://browserify.org/
660 changes: 319 additions & 341 deletions lib/chai-as-promised.js

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
"test": "npm run test-plugin && npm run test-intercompatibility",
"test-plugin": "mocha",
"test-intercompatibility": "mocha test-intercompatibility --opts test-intercompatibility/mocha.opts",
"test-browser-jquery": "coffee ./test/browser/runner.coffee jquery",
"test-browser-q": "coffee ./test/browser/runner.coffee q",
"test-browser-when": "coffee ./test/browser/runner.coffee when",
"lint": "jshint ./lib",
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/chai-as-promised.js.html"
},
"peerDependencies": {
"chai": ">= 2.1.2 < 4",
"dependencies": {
"check-error": "^1.0.2"
},
"peerDependencies": {
"chai": ">= 2.1.2 < 4"
},
"devDependencies": {
"chai": "^3.0.0",
"coffee-script": "1.10.0",
Expand Down
1 change: 1 addition & 0 deletions test/assert-eventually.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict"
{ shouldPass, shouldFail } = require("./support/common.js")

describe "Assert interface with eventually extender:", =>
promise = null
Expand Down
1 change: 1 addition & 0 deletions test/assert-promise-specific.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict"
{ shouldPass, shouldFail } = require("./support/common.js")

describe "Assert interface:", =>
promise = null
Expand Down
36 changes: 0 additions & 36 deletions test/browser/libraries/jquery.coffee

This file was deleted.

12 changes: 0 additions & 12 deletions test/browser/libraries/q.coffee

This file was deleted.

29 changes: 0 additions & 29 deletions test/browser/libraries/when.coffee

This file was deleted.

28 changes: 0 additions & 28 deletions test/browser/runner.coffee

This file was deleted.

37 changes: 0 additions & 37 deletions test/browser/template.html

This file was deleted.

1 change: 1 addition & 0 deletions test/custom-messages.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict"
{ shouldPass, shouldFail } = require("./support/common.js")

describe "Custom messages", =>
promise = null
Expand Down
1 change: 1 addition & 0 deletions test/should-eventually.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict"
{ shouldPass, shouldFail } = require("./support/common.js")

describe "Fulfillment value assertions:", =>
promise = null
Expand Down
1 change: 1 addition & 0 deletions test/should-promise-specific.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict"
{ shouldPass, shouldFail } = require("./support/common.js")

describe "Promise-specific extensions:", =>
promise = null
Expand Down
9 changes: 0 additions & 9 deletions test/support/browser.js

This file was deleted.

13 changes: 2 additions & 11 deletions test/support/common.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
"use strict";

// Note: this file is used both in the Node and browser tests.

(function () {
var Q = global.Q || (typeof require === "function" && require("q"));
if (Q) {
Q.longStackSupport = true;
}
}());

global.shouldPass = function (promiseProducer) {
exports.shouldPass = function (promiseProducer) {
it("should return a fulfilled promise", function (done) {
promiseProducer().then(
function () {
Expand All @@ -22,7 +13,7 @@ global.shouldPass = function (promiseProducer) {
});
};

global.shouldFail = function (options) {
exports.shouldFail = function (options) {
var promiseProducer = options.op;
var desiredMessageSubstring = options.message;
var nonDesiredMessageSubstring = options.notMessage;
Expand Down

0 comments on commit bb51e07

Please sign in to comment.