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
37 changes: 37 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
'parser': 'typescript-eslint-parser',
'globals': {
'Pretender': true,
'sinon': true, // karma-sinon
},
'env': {
'browser': true,
'es6': true,
'node': true,
'jquery': true,
'qunit': true,
},
'extends': 'eslint:recommended',
'parserOptions': {
'ecmaVersion': 2015,
'sourceType': 'module'
},
'rules': {
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'always'
]
}
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bower_components
node_modules
coverage*
coverage*
dist
41 changes: 0 additions & 41 deletions .jscsrc

This file was deleted.

3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
sudo: false
language: node_js
node_js:
- "4.2"
- "5"
- "6"
- "8"
- "10"

before_install:
- "npm config set spin false"
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ with an express/sinatra style syntax for defining routes and their handlers.
Pretender will temporarily replace native XMLHttpRequest and Fetch , intercept
all requests, and direct them to little pretend service you've defined.

**:warning: Pretender only works in the browser!**

```javascript
const PHOTOS = {
"10": {
Expand All @@ -40,6 +38,23 @@ const server = new Pretender(function() {
$.get('/photos/12', {success() => { ... }})
```

## Usage examples

You can load Pretender directly in the browser.

```javascript
<script src="pretender.js"></script>
```

Or as a module.

```javascript
import Pretender from 'pretender';
const server = new Pretender(function() {});
```

Full example: [use-pretender-as-a-module](https://github.com/givanse/use-pretender-as-a-module)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the repo linked here, I added as collaborators the people that have merge access to Pretender.

Or if you prefer me to delete the mention of 'use-pretender-as-a-module', that is fine, I will.


## The Server DSL
The server DSL is inspired by express/sinatra. Pass a function to the Pretender constructor
that will be invoked with the Pretender instance as its context. Available methods are
Expand Down
30 changes: 27 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Karma configuration
// Generated on Thu Oct 06 2016 14:24:14 GMT+0800 (PHT)
const typescript = require('rollup-plugin-typescript');

module.exports = function(config) {
config.set({
Expand All @@ -21,9 +22,13 @@ module.exports = function(config) {
'bower_components/jquery/dist/jquery.js',
'node_modules/es6-promise/dist/es6-promise.auto.js',
'node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js',
'node_modules/@xg-wang/whatwg-fetch/dist/fetch.umd.js',
'node_modules/whatwg-fetch/dist/fetch.umd.js',
'pretender.js',
'test/**/*.js'
/**
* Make sure to disable Karma’s file watcher
* because the preprocessor will use its own.
*/
{ pattern: 'test/**/*_test.[j|t]s', watched: false }
],

// list of files to exclude
Expand All @@ -35,7 +40,26 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'pretender.js': ['coverage']
'pretender.js': ['coverage'],
'test/**/*_test.[j|t]s': ['rollup'],
},
rollupPreprocessor: {
/**
* This is just a normal Rollup config object,
* except that `input` is handled for you.
*/
external: ['QUnit'],
plugins: [
typescript()
],
output: {
format: 'iife', // Helps prevent naming collisions.
name: 'pretendertests', // Required for 'iife' format.
sourcemap: 'inline', // Sensible for testing.
globals: [
'Qunit',
],
},
},

coverageReporter: {
Expand Down
Loading