-
-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(utils): start adding tests for changed utils
- Loading branch information
1 parent
76c5a03
commit ac17350
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
context: path.resolve(__dirname), | ||
entry: './simple.js', | ||
output: { | ||
filename: 'bundle.js', | ||
path: path.resolve(__dirname, '../outputs/public-path'), | ||
publicPath: '/public/path/', | ||
}, | ||
infrastructureLogging: { | ||
level: 'none' | ||
}, | ||
stats: 'errors-warnings' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default (app, compiler, done) => { | ||
let complete = 0; | ||
// wait until the app is listening and the done hook is called | ||
const progress = () => { | ||
complete += 1; | ||
if (complete === 2) { | ||
done(); | ||
} | ||
}; | ||
|
||
const listen = app.listen((error) => { | ||
if (error) { | ||
// if there is an error, don't wait for the compilation to finish | ||
return done(error); | ||
} | ||
|
||
return progress(); | ||
}); | ||
|
||
compiler.hooks.done.tap('wdm-test', () => { | ||
return progress(); | ||
}); | ||
|
||
return listen; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// import getFilenameFromUrl from '../../src/utils/getFilenameFromUrl'; | ||
|
||
describe('getFilenameFromUrl', () => { | ||
it('should work', () => { | ||
// TODO | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import path from 'path'; | ||
|
||
import express from 'express'; | ||
|
||
import middleware from '../../src'; | ||
import getPaths from '../../src/utils/getPaths'; | ||
|
||
import getCompiler from '../helpers/getCompiler'; | ||
import listenAndCompile from '../helpers/listenAndCompile'; | ||
import webpackSimpleConfig from '../fixtures/webpack.simple.config'; | ||
import webpackPublicPathConfig from '../fixtures/webpack.public-path.config'; | ||
import webpackMultiConfig from '../fixtures/webpack.array.config'; | ||
|
||
describe('getPaths', () => { | ||
let instance; | ||
let listen; | ||
let app; | ||
let compiler; | ||
|
||
const configs = [ | ||
{ | ||
title: 'simple config', | ||
config: webpackSimpleConfig, | ||
expected: [ | ||
{ | ||
outputPath: path.resolve(__dirname, '../outputs/simple'), | ||
publicPath: '', | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'publicPath config', | ||
config: webpackPublicPathConfig, | ||
expected: [ | ||
{ | ||
outputPath: path.resolve(__dirname, '../outputs/public-path'), | ||
publicPath: '/public/path/', | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'multi config', | ||
config: webpackMultiConfig, | ||
expected: [ | ||
{ | ||
outputPath: path.resolve(__dirname, '../outputs/array/js1'), | ||
publicPath: '/static-one/', | ||
}, | ||
{ | ||
outputPath: path.resolve(__dirname, '../outputs/array/js2'), | ||
publicPath: '/static-two/', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
configs.forEach((config) => { | ||
describe(config.title, () => { | ||
beforeEach((done) => { | ||
compiler = getCompiler(config.config); | ||
|
||
instance = middleware(compiler); | ||
|
||
app = express(); | ||
app.use(instance); | ||
|
||
listen = listenAndCompile(app, compiler, done); | ||
}); | ||
|
||
afterEach((done) => { | ||
if (instance) { | ||
instance.close(); | ||
} | ||
|
||
if (listen) { | ||
listen.close(done); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
|
||
it('should return correct paths', () => { | ||
expect(getPaths(instance.context)).toEqual(config.expected); | ||
}); | ||
}); | ||
}); | ||
}); |