-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add jsonp middleware for mock #8
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(1); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"spm": { | ||
"output": [ | ||
"a.js" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello": "world" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,55 @@ var fs = require('fs'); | |
var existsSync = fs.existsSync; | ||
var readFileSync = fs.readFileSync; | ||
|
||
describe('server-with-jsonp', function() { | ||
|
||
var app = null; | ||
var args = null; | ||
|
||
before(function (done) { | ||
args = { | ||
cwd : join(fixtures, 'server-with-jsonp'), | ||
jsonp : true, | ||
debug : true | ||
}; | ||
process.chdir(args.cwd); | ||
var pkgFile = join(args.cwd, 'package.json'); | ||
if (existsSync(pkgFile)) { | ||
args.pkg = JSON.parse(readFileSync(pkgFile, 'utf-8')); | ||
} | ||
console.log(args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 调试代码? |
||
sw.build.getWebpackOpts(args, function (err, webpackOpts) { | ||
var server = new Server(sw.webpack(webpackOpts), args); | ||
app = server.app; | ||
server.once('done', done); | ||
}); | ||
}); | ||
|
||
it('get /x.json', function(done) { | ||
request(app.listen()) | ||
.get('/x.json') | ||
.expect(function(res){ | ||
if(res.text.should.be.eql('{\n "hello": "world"\n}\n') === 0) throw new Error('Can not get right json content'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
.end(function(err){ | ||
if (err) return done(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('get /x.json?callback=t', function(done) { | ||
request(app.listen()) | ||
.get('/x.json?callback=t') | ||
.expect(function(res){ | ||
if(res.text.should.be.eql(';t({\n "hello": "world"\n}\n);') === 0) throw new Error('Can not get right jsonp content'); | ||
}) | ||
.end(function(err){ | ||
if (err) return done(err); | ||
done(); | ||
}); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少 pkg.spm.jsonp 用例 |
||
}); | ||
|
||
describe('server-with-pkg-name', function() { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放在 server 里? 另外,opts.pkg.spm.jsonp 要做兼容,pkg 和 spm 都有可能不存在。