Skip to content

Commit

Permalink
Merge a534976 into 1b9e1de
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 committed Dec 17, 2020
2 parents 1b9e1de + a534976 commit a017524
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 49 deletions.
1 change: 0 additions & 1 deletion docs/config/02-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Each pattern is either a simple string or an object with the following propertie
* `css` - Include using `<link rel="stylesheet">` tag.
* `html` - Include using [HTML Imports](https://developer.mozilla.org/en-US/docs/Web/Web_Components/HTML_Imports). Note that this feature is obsolete and does not work in the modern browsers.
* `js` - Include using `<script></script>` tag.
* `dart` - Include using `<script type="application/dart"></script>` tag. Note that this does not work in the modern browsers.
* `module` - Include using `<script type="module"></script>` tag.
* `dom` - Inline content of the file in the page. This can be used, for example, to test components combining HTML and JS.
* **Description.** The type determines the mechanism for including the file.
Expand Down
3 changes: 1 addition & 2 deletions docs/dev/05-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A preprocessor is a function that accepts three arguments (`content`, `file`, an
- user NPM keywords `karma-plugin`, `karma-preprocessor`

## Crazier stuff
Karma is assembled by Dependency Injection and a plugin is just an additional DI module (see [node-di] for more), that can be loaded by Karma. Therefore, it can ask for pretty much any Karma component and interact with it. There are a couple of plugins that do more interesting stuff like this, check out [karma-closure], [karma-intellij], [karma-dart].
Karma is assembled by Dependency Injection and a plugin is just an additional DI module (see [node-di] for more), that can be loaded by Karma. Therefore, it can ask for pretty much any Karma component and interact with it. There are a couple of plugins that do more interesting stuff like this, check out [karma-closure], [karma-intellij].


[karma-jasmine]: https://github.com/karma-runner/karma-jasmine
Expand All @@ -49,7 +49,6 @@ Karma is assembled by Dependency Injection and a plugin is just an additional DI
[karma-ng-html2js-preprocessor]: https://github.com/karma-runner/karma-ng-html2js-preprocessor
[karma-closure]: https://github.com/karma-runner/karma-closure
[karma-intellij]: https://github.com/karma-runner/karma-intellij
[karma-dart]: https://github.com/karma-runner/karma-dart
[node-di]: https://github.com/vojtajina/node-di
[karma-material-reporter]: https://github.com/ameerthehacker/karma-material-reporter

Expand Down
2 changes: 0 additions & 2 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const common = require('./common')
const VERSION = require('../constants').VERSION
const SCRIPT_TYPE = {
js: 'text/javascript',
dart: 'application/dart',
module: 'module'
}
const FILE_TYPES = [
'css',
'html',
'js',
'dart',
'module',
'dom'
]
Expand Down
4 changes: 0 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class Server extends KarmaEventEmitter {
filesPromise: ['factory', createFilesPromise],
socketServer: ['factory', createSocketIoServer],
executor: ['factory', Executor.factory],
// TODO(vojta): remove
customFileHandlers: ['value', []],
// TODO(vojta): remove, once karma-dart does not rely on it
customScriptTypes: ['value', []],
reporter: ['factory', reporter.createReporters],
capturedBrowsers: ['factory', BrowserCollection.factory],
args: ['value', {}],
Expand Down
14 changes: 0 additions & 14 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ const proxyMiddleware = require('./middleware/proxy')

const log = require('./logger').create('web-server')

function createCustomHandler (customFileHandlers, config) {
return function (request, response, next) {
const handler = customFileHandlers.find((handler) => handler.urlRegex.test(request.url))
return handler
? handler.handler(request, response, 'fake/static', 'fake/adapter', config.basePath, 'fake/root')
: next()
}
}

createCustomHandler.$inject = ['customFileHandlers', 'config']

function createFilesPromise (emitter, fileList) {
// Set an empty list of files to avoid race issues with
// file_list_modified not having been emitted yet
Expand Down Expand Up @@ -69,9 +58,6 @@ function createWebServer (injector, config) {
handler.use(injector.invoke(sourceFilesMiddleware.create))
// TODO(vojta): extract the proxy into a plugin
handler.use(proxyMiddlewareInstance)
// TODO(vojta): remove, this is only here because of karma-dart
// we need a better way of custom handlers
handler.use(injector.invoke(createCustomHandler))

if (config.middleware) {
config.middleware.forEach((middleware) => handler.use(injector.get('middleware:' + middleware)))
Expand Down
4 changes: 2 additions & 2 deletions test/unit/middleware/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ describe('middleware.karma', () => {
it('should serve context.html with replaced script tags', (done) => {
includedFiles([
new MockFile('/first.js', 'sha123'),
new MockFile('/second.dart', 'sha456')
new MockFile('/second.js', 'sha456')
])

response.once('end', () => {
expect(nextSpy).not.to.have.been.called
expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/first.js?sha123" crossorigin="anonymous"></script>\n<script type="application/dart" src="/__proxy__/__karma__/absolute/second.dart?sha456" crossorigin="anonymous"></script>')
expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/first.js?sha123" crossorigin="anonymous"></script>\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/second.js?sha456" crossorigin="anonymous"></script>')
done()
})

Expand Down
25 changes: 1 addition & 24 deletions test/unit/web-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('web-server', () => {
// NOTE(vojta): only loading once, to speed things up
// this relies on the fact that none of these tests mutate fs
const m = mocks.loadFile(path.join(__dirname, '/../../lib/web-server.js'), _mocks, _globals)
let customFileHandlers = server = emitter = null
server = emitter = null
let beforeMiddlewareActive = false
let middlewareActive = false
const servedFiles = (files) => {
Expand All @@ -40,7 +40,6 @@ describe('web-server', () => {

describe('request', () => {
beforeEach(() => {
customFileHandlers = []
emitter = new EventEmitter()
const config = {
basePath: '/base/path',
Expand All @@ -57,7 +56,6 @@ describe('web-server', () => {

const injector = new di.Injector([{
config: ['value', config],
customFileHandlers: ['value', customFileHandlers],
emitter: ['value', emitter],
fileList: ['value', { files: { served: [], included: [] } }],
filesPromise: ['factory', m.createFilesPromise],
Expand Down Expand Up @@ -182,23 +180,6 @@ describe('web-server', () => {
})
})

it('should load custom handlers', () => {
servedFiles(new Set())

// TODO(vojta): change this, only keeping because karma-dart is relying on it
customFileHandlers.push({
urlRegex: /\/some\/weird/,
handler (request, response, staticFolder, adapterFolder, baseFolder, urlRoot) {
response.writeHead(222)
response.end('CONTENT')
}
})

return request(server)
.get('/some/weird/url')
.expect(222, 'CONTENT')
})

it('should serve 404 for non-existing files', () => {
servedFiles(new Set())

Expand All @@ -215,7 +196,6 @@ describe('web-server', () => {
cert: fs.readFileSync(path.join(__dirname, '/certificates/server.crt'))
}

customFileHandlers = []
emitter = new EventEmitter()

const injector = new di.Injector([{
Expand All @@ -226,7 +206,6 @@ describe('web-server', () => {
httpsServerOptions: credentials,
client: { useIframe: true, useSingleWindow: false }
}],
customFileHandlers: ['value', customFileHandlers],
emitter: ['value', emitter],
fileList: ['value', { files: { served: [], included: [] } }],
filesPromise: ['factory', m.createFilesPromise],
Expand Down Expand Up @@ -265,12 +244,10 @@ describe('web-server', () => {
cert: fs.readFileSync(path.join(__dirname, '/certificates/server.crt'))
}

customFileHandlers = []
emitter = new EventEmitter()

const injector = new di.Injector([{
config: ['value', { basePath: '/base/path', urlRoot: '/', httpModule: http2, protocol: 'https:', httpsServerOptions: credentials }],
customFileHandlers: ['value', customFileHandlers],
emitter: ['value', emitter],
fileList: ['value', { files: { served: [], included: [] } }],
filesPromise: ['factory', m.createFilesPromise],
Expand Down

0 comments on commit a017524

Please sign in to comment.