Visitar URL original
Refactored Karma tests to use rollup preprocessor & ESM; · axios/axios@b114f1f · GitHub
Skip to content

Commit b114f1f

Browse files
Refactored Karma tests to use rollup preprocessor & ESM;
Replaced grunt with gulp; Improved dev scripts; Added Babel for rollup build;
1 parent be2ad1d commit b114f1f

67 files changed

Lines changed: 16316 additions & 14853 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.

‎Gruntfile.js‎

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

‎bin/ssl_hotfix.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {spawn} = require('child_process');
1+
import {spawn} from 'child_process';
22

33
const args = process.argv.slice(2);
44

‎examples/get/server.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var people = [
1+
const people = [
22
{
33
"name": "Matt Zabriskie",
44
"github": "mzabriskie",
@@ -25,7 +25,7 @@ var people = [
2525
}
2626
];
2727

28-
module.exports = function (req, res) {
28+
export default function (req, res) {
2929
res.writeHead(200, {
3030
'Content-Type': 'text/json'
3131
});

‎examples/post/server.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = function (req, res) {
2-
var data = '';
1+
export default function (req, res) {
2+
let data = '';
33

44
req.on('data', function (chunk) {
55
data += chunk;

‎examples/postMultipartFormData/server.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function (req, res) {
1+
export default function (req, res) {
22

33
req.on('data', function (chunk) {
44
});

‎examples/server.js‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
var fs = require('fs');
2-
var path = require('path');
3-
var http = require('http');
4-
var argv = require('minimist')(process.argv.slice(2));
5-
var server;
6-
var dirs;
1+
import fs from 'fs';
2+
import path from 'path';
3+
import http from 'http';
4+
import minimist from 'minimist';
5+
import url from "url";
6+
const argv = minimist(process.argv.slice(2));
7+
let server;
8+
let dirs;
9+
10+
const __filename = url.fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
712

813
function listDirs(root) {
9-
var files = fs.readdirSync(root);
10-
var dirs = [];
14+
const files = fs.readdirSync(root);
15+
const dirs = [];
1116

12-
for (var i = 0, l = files.length; i < l; i++) {
13-
var file = files[i];
17+
for (let i = 0, l = files.length; i < l; i++) {
18+
const file = files[i];
1419
if (file[0] !== '.') {
15-
var stat = fs.statSync(path.join(root, file));
20+
const stat = fs.statSync(path.join(root, file));
1621
if (stat.isDirectory()) {
1722
dirs.push(file);
1823
}
@@ -23,8 +28,8 @@ function listDirs(root) {
2328
}
2429

2530
function getIndexTemplate() {
26-
var links = dirs.map(function (dir) {
27-
var url = '/' + dir;
31+
const links = dirs.map(function (dir) {
32+
const url = '/' + dir;
2833
return '<li onclick="document.location=\'' + url + '\'"><a href="' + url + '">' + url + '</a></li>';
2934
});
3035

@@ -74,7 +79,7 @@ function pipeFileToResponse(res, file, type) {
7479
dirs = listDirs(__dirname);
7580

7681
server = http.createServer(function (req, res) {
77-
var url = req.url;
82+
let url = req.url;
7883

7984
// Process axios itself
8085
if (/axios\.min\.js$/.test(url)) {
@@ -106,7 +111,7 @@ server = http.createServer(function (req, res) {
106111
}
107112

108113
// Format request /get -> /get/index.html
109-
var parts = url.split('/');
114+
const parts = url.split('/');
110115
if (dirs.indexOf(parts[parts.length - 1]) > -1) {
111116
url += '/index.html';
112117
}
@@ -136,5 +141,5 @@ server = http.createServer(function (req, res) {
136141
const PORT = argv.p || 3000;
137142

138143
server.listen(PORT, () => {
139-
console.log(`Examples running on ${PORT}`);
144+
console.log(`Examples running on ${PORT}`);
140145
});

‎examples/upload/server.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = function (req, res) {
2-
var data = '';
1+
export default function (req, res) {
2+
let data = '';
33

44
req.on('data', function (chunk) {
55
data += chunk;

‎gulpfile.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import gulp from 'gulp';
2+
import fs from 'fs-extra';
3+
4+
gulp.task('default', async function(){
5+
console.log('hello!');
6+
});
7+
8+
const clear = gulp.task('clear', async function() {
9+
await fs.emptyDir('./dist/')
10+
});
11+
12+
const bower = gulp.task('bower', async function () {
13+
const npm = JSON.parse(await fs.readFile('package.json'));
14+
const bower = JSON.parse(await fs.readFile('bower.json'));
15+
16+
const fields = [
17+
'name',
18+
'description',
19+
'version',
20+
'homepage',
21+
'license',
22+
'keywords'
23+
];
24+
25+
for (let i = 0, l = fields.length; i < l; i++) {
26+
const field = fields[i];
27+
bower[field] = npm[field];
28+
}
29+
30+
await fs.writeFile('bower.json', JSON.stringify(bower, null, 2));
31+
});
32+
33+
const env = gulp.task('env', async function () {
34+
var npm = JSON.parse(await fs.readFile('package.json'));
35+
36+
await fs.writeFile('./lib/env/data.js', Object.entries({
37+
VERSION: npm.version
38+
}).map(([key, value]) => {
39+
return `export const ${key} = ${JSON.stringify(value)};`
40+
}).join('\n'));
41+
});
42+
43+
const version = gulp.parallel('bower', 'env');
44+
45+
export {
46+
bower,
47+
env,
48+
clear,
49+
version
50+
}

karma.conf.js renamed to karma.conf.cjs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
'use strict';
88

9-
var webpack = require('webpack');
9+
var resolve = require('@rollup/plugin-node-resolve').default;
10+
var commonjs = require('@rollup/plugin-commonjs');
1011

1112
function createCustomLauncher(browser, version, platform) {
1213
return {
@@ -147,8 +148,8 @@ module.exports = function(config) {
147148

148149
// list of files / patterns to load in the browser
149150
files: [
150-
'test/specs/__helpers.js',
151-
'test/specs/**/*.spec.js'
151+
{pattern: 'test/specs/__helpers.js', watched: false},
152+
{pattern: 'test/specs/**/*.spec.js', watched: false}
152153
],
153154

154155

@@ -159,8 +160,20 @@ module.exports = function(config) {
159160
// preprocess matching files before serving them to the browser
160161
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
161162
preprocessors: {
162-
'test/specs/__helpers.js': ['webpack', 'sourcemap'],
163-
'test/specs/**/*.spec.js': ['webpack', 'sourcemap']
163+
'test/specs/__helpers.js': ['rollup'],
164+
'test/specs/**/*.spec.js': ['rollup']
165+
},
166+
167+
rollupPreprocessor: {
168+
plugins: [
169+
resolve({browser: true}),
170+
commonjs()
171+
],
172+
output: {
173+
format: 'iife',
174+
name: '_axios',
175+
sourcemap: 'inline'
176+
}
164177
},
165178

166179

0 commit comments

Comments
 (0)