Skip to content

Commit d203dac

Browse files
committed
Publish pretender.bundle.js bundling dependencies
dist/pretender.bundle.js is an iife build with fake-xml-http-request and route-recognizer bundled to make installation easier The default main entry in package.json remains same for compatibility. Both bundle build and non bundle builds are tested in ci.
1 parent b38a2b0 commit d203dac

File tree

6 files changed

+88
-69
lines changed

6 files changed

+88
-69
lines changed

.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
language: node_js
22
node_js:
3-
- "12"
3+
- "14"
44

55
addons:
66
chrome: stable
77

8-
script: yarn run test-ci
8+
script:
9+
- yarn run test-ci
10+
- NO_BUNDLE=true yarn run test-ci
911

1012
after_script:
1113
- find ./coverage/HeadlessChrome* -name "lcov.info" -exec cat {} \; | coveralls

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ npm install --save-dev pretender
5252
You can load Pretender directly in the browser.
5353

5454
```javascript
55-
<script src="pretender.js"></script>
55+
<script src="node_modules/pretender/dist/pretender.bundle.js"></script>
5656
```
5757

58-
Or as a module.
58+
Or as a module:
5959

6060
```javascript
6161
import Pretender from 'pretender';
@@ -118,7 +118,7 @@ const server = new Pretender(function() {
118118

119119
// typical jQuery-style uses you've probably seen.
120120
// queryParams.sortOrder will be 'asc' for both styles.
121-
$.get({url: '/api/songs', data: { sortOrder: 'asc' });
121+
$.get({url: '/api/songs', data: { sortOrder: 'asc' }});
122122
$.get('/api/songs?sortOrder=asc');
123123

124124
```
@@ -476,8 +476,8 @@ server.shutdown(); // all done.
476476

477477
## Running tests
478478

479-
* `npm test` runs tests once
480-
* `npm run test:server` runs and reruns on changes
479+
* `yarn test` runs tests once
480+
* `yarn test:server` runs and reruns on changes
481481

482482
## Code of Conduct
483483

karma.conf.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,80 @@
11
// Karma configuration
22
// Generated on Thu Oct 06 2016 14:24:14 GMT+0800 (PHT)
33

4-
module.exports = function(config) {
4+
module.exports = function (config) {
55
config.set({
6-
76
// base path that will be used to resolve all patterns (eg. files, exclude)
8-
basePath: '',
9-
10-
plugins: ['karma-jquery', 'karma-qunit', 'karma-coverage', 'karma-sinon', 'karma-chrome-launcher'],
7+
basePath: "",
8+
9+
plugins: [
10+
"karma-jquery",
11+
"karma-qunit",
12+
"karma-coverage",
13+
"karma-sinon",
14+
"karma-chrome-launcher",
15+
],
1116

1217
// frameworks to use
1318
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
14-
frameworks: ['qunit', 'sinon', 'jquery-3.4.0'],
19+
frameworks: ["qunit", "sinon", "jquery-3.4.0"],
1520

1621
// list of files / patterns to load in the browser
17-
files: [
18-
'node_modules/fake-xml-http-request/fake_xml_http_request.js',
19-
'node_modules/route-recognizer/dist/route-recognizer.js',
20-
'node_modules/es6-promise/dist/es6-promise.auto.js',
21-
'node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js',
22-
'node_modules/whatwg-fetch/dist/fetch.umd.js',
23-
'dist/pretender.js',
24-
'test/**/*.js'
25-
],
22+
files: (process.env.NO_BUNDLE
23+
? [
24+
"node_modules/fake-xml-http-request/fake_xml_http_request.js",
25+
"node_modules/route-recognizer/dist/route-recognizer.js",
26+
"dist/pretender.js",
27+
]
28+
: ["dist/pretender.bundle.js"]
29+
).concat([
30+
"node_modules/es6-promise/dist/es6-promise.auto.js",
31+
"node_modules/abortcontroller-polyfill/dist/abortcontroller-polyfill-only.js",
32+
"test/**/*.js",
33+
]),
2634

2735
// preprocess matching files before serving them to the browser
2836
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
2937
preprocessors: {
30-
'dist/pretender.js': ['coverage']
38+
"dist/pretender.js": ["coverage"],
3139
},
3240

3341
coverageReporter: {
34-
type: 'lcov',
35-
dir: 'coverage'
42+
type: "lcov",
43+
dir: "coverage",
3644
},
3745

38-
3946
// test results reporter to use
4047
// possible values: 'dots', 'progress'
4148
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
42-
reporters: ['dots', 'coverage'],
43-
49+
reporters: ["dots", "coverage"],
4450

4551
// web server port
4652
port: 9876,
4753

48-
4954
// enable / disable colors in the output (reporters and logs)
5055
colors: true,
5156

52-
5357
// level of logging
5458
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
5559
logLevel: config.LOG_INFO,
5660

57-
5861
// enable / disable watching file and executing tests whenever any file changes
5962
autoWatch: true,
6063

61-
6264
// start these browsers
6365
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
64-
browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessNoSandbox'],
66+
browsers: ["Chrome", "ChromeHeadless", "ChromeHeadlessNoSandbox"],
6567

6668
// you can define custom flags
6769
customLaunchers: {
6870
ChromeHeadlessNoSandbox: {
69-
base: 'ChromeHeadless',
70-
flags: ['--no-sandbox']
71-
}
71+
base: "ChromeHeadless",
72+
flags: ["--no-sandbox"],
73+
},
7274
},
7375

7476
// Continuous Integration mode
7577
// if true, Karma captures browsers, runs the tests and exits
76-
singleRun: false
78+
singleRun: false,
7779
});
7880
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,9 @@
7070
"exports": "Pretender"
7171
}
7272
}
73+
},
74+
"volta": {
75+
"node": "14.2.0",
76+
"yarn": "1.22.4"
7377
}
7478
}

rollup.config.js

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
1-
const commonjs = require('@rollup/plugin-commonjs');
2-
const resolve = require('@rollup/plugin-node-resolve');
3-
const typescript = require('rollup-plugin-typescript');
4-
const pkg = require('./package.json');
5-
const fs = require('fs');
1+
import commonjs from "@rollup/plugin-commonjs";
2+
import resolve from "@rollup/plugin-node-resolve";
3+
import typescript from "rollup-plugin-typescript";
4+
import { readFileSync } from "fs";
5+
import pkg from "./package.json";
6+
67
const globals = {
7-
'fake-xml-http-request': 'FakeXMLHttpRequest',
8-
'route-recognizer': 'RouteRecognizer',
9-
'url-parse': 'urlParse'
8+
"fake-xml-http-request": "FakeXMLHttpRequest",
9+
"route-recognizer": "RouteRecognizer",
10+
"url-parse": "urlParse",
1011
};
1112

12-
const rollupTemplate = fs.readFileSync('./iife-wrapper.js').toString();
13-
const [banner, footer] = rollupTemplate.split('/*==ROLLUP_CONTENT==*/');
13+
const rollupTemplate = readFileSync("./iife-wrapper.js").toString();
14+
const [banner, footer] = rollupTemplate.split("/*==ROLLUP_CONTENT==*/");
1415

15-
module.exports = {
16-
input: 'src/index.ts',
17-
external: Object.keys(pkg.dependencies),
18-
output: [
19-
{
20-
name: 'Pretender',
21-
file: pkg.main,
22-
format: 'iife',
23-
globals,
24-
banner,
25-
footer
26-
},
27-
{
28-
file: pkg.module,
29-
format: 'es'
30-
}
31-
],
32-
plugins: [commonjs(), resolve(), typescript()]
33-
};
16+
module.exports = [
17+
{
18+
input: "src/index.ts",
19+
external: Object.keys(pkg.dependencies),
20+
output: [
21+
{
22+
name: "Pretender",
23+
file: pkg.main,
24+
format: "iife",
25+
globals,
26+
banner,
27+
footer,
28+
},
29+
{
30+
file: pkg.module,
31+
format: "es",
32+
},
33+
],
34+
plugins: [commonjs(), resolve(), typescript()],
35+
},
36+
{
37+
input: "src/index.ts",
38+
output: [
39+
{
40+
file: "./dist/pretender.bundle.js",
41+
name: "Pretender",
42+
format: "iife",
43+
}
44+
],
45+
plugins: [commonjs(), resolve(), typescript()],
46+
},
47+
];

0 commit comments

Comments
 (0)