Skip to content

Commit 7a3bd55

Browse files
authoredDec 17, 2020
feat: remove support for running dart code in the browser (#3592)
As Dartium browser is no more, there are no browsers left, which support running Dart applications natively and therefore we can remove such support from Karma to reduce the maintenance effort. BREAKING CHANGE: Using Karma to run Dart code in the browser is no longer supported. Use your favorite Dart-to-JS compiler instead. `dart` file type has been removed without a replacement. `customFileHandlers` DI token has been removed. Use [`middleware`](http://karma-runner.github.io/5.2/config/configuration-file.html#middleware) to achieve similar functionality. `customScriptTypes` DI token has been removed. It had no effect, so no replacement is provided.
1 parent 1b9e1de commit 7a3bd55

File tree

7 files changed

+4
-49
lines changed

7 files changed

+4
-49
lines changed
 

‎docs/config/02-files.md

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Each pattern is either a simple string or an object with the following propertie
3131
* `css` - Include using `<link rel="stylesheet">` tag.
3232
* `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.
3333
* `js` - Include using `<script></script>` tag.
34-
* `dart` - Include using `<script type="application/dart"></script>` tag. Note that this does not work in the modern browsers.
3534
* `module` - Include using `<script type="module"></script>` tag.
3635
* `dom` - Inline content of the file in the page. This can be used, for example, to test components combining HTML and JS.
3736
* **Description.** The type determines the mechanism for including the file.

‎docs/dev/05-plugins.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A preprocessor is a function that accepts three arguments (`content`, `file`, an
3434
- user NPM keywords `karma-plugin`, `karma-preprocessor`
3535

3636
## Crazier stuff
37-
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].
37+
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].
3838

3939

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

‎lib/middleware/karma.js

-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ const common = require('./common')
2020
const VERSION = require('../constants').VERSION
2121
const SCRIPT_TYPE = {
2222
js: 'text/javascript',
23-
dart: 'application/dart',
2423
module: 'module'
2524
}
2625
const FILE_TYPES = [
2726
'css',
2827
'html',
2928
'js',
30-
'dart',
3129
'module',
3230
'dom'
3331
]

‎lib/server.js

-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ class Server extends KarmaEventEmitter {
8282
filesPromise: ['factory', createFilesPromise],
8383
socketServer: ['factory', createSocketIoServer],
8484
executor: ['factory', Executor.factory],
85-
// TODO(vojta): remove
86-
customFileHandlers: ['value', []],
87-
// TODO(vojta): remove, once karma-dart does not rely on it
88-
customScriptTypes: ['value', []],
8985
reporter: ['factory', reporter.createReporters],
9086
capturedBrowsers: ['factory', BrowserCollection.factory],
9187
args: ['value', {}],

‎lib/web-server.js

-14
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ const proxyMiddleware = require('./middleware/proxy')
1616

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

19-
function createCustomHandler (customFileHandlers, config) {
20-
return function (request, response, next) {
21-
const handler = customFileHandlers.find((handler) => handler.urlRegex.test(request.url))
22-
return handler
23-
? handler.handler(request, response, 'fake/static', 'fake/adapter', config.basePath, 'fake/root')
24-
: next()
25-
}
26-
}
27-
28-
createCustomHandler.$inject = ['customFileHandlers', 'config']
29-
3019
function createFilesPromise (emitter, fileList) {
3120
// Set an empty list of files to avoid race issues with
3221
// file_list_modified not having been emitted yet
@@ -69,9 +58,6 @@ function createWebServer (injector, config) {
6958
handler.use(injector.invoke(sourceFilesMiddleware.create))
7059
// TODO(vojta): extract the proxy into a plugin
7160
handler.use(proxyMiddlewareInstance)
72-
// TODO(vojta): remove, this is only here because of karma-dart
73-
// we need a better way of custom handlers
74-
handler.use(injector.invoke(createCustomHandler))
7561

7662
if (config.middleware) {
7763
config.middleware.forEach((middleware) => handler.use(injector.get('middleware:' + middleware)))

‎test/unit/middleware/karma.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ describe('middleware.karma', () => {
202202
it('should serve context.html with replaced script tags', (done) => {
203203
includedFiles([
204204
new MockFile('/first.js', 'sha123'),
205-
new MockFile('/second.dart', 'sha456')
205+
new MockFile('/second.js', 'sha456')
206206
])
207207

208208
response.once('end', () => {
209209
expect(nextSpy).not.to.have.been.called
210-
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>')
210+
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>')
211211
done()
212212
})
213213

‎test/unit/web-server.spec.js

+1-24
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('web-server', () => {
3131
// NOTE(vojta): only loading once, to speed things up
3232
// this relies on the fact that none of these tests mutate fs
3333
const m = mocks.loadFile(path.join(__dirname, '/../../lib/web-server.js'), _mocks, _globals)
34-
let customFileHandlers = server = emitter = null
34+
server = emitter = null
3535
let beforeMiddlewareActive = false
3636
let middlewareActive = false
3737
const servedFiles = (files) => {
@@ -40,7 +40,6 @@ describe('web-server', () => {
4040

4141
describe('request', () => {
4242
beforeEach(() => {
43-
customFileHandlers = []
4443
emitter = new EventEmitter()
4544
const config = {
4645
basePath: '/base/path',
@@ -57,7 +56,6 @@ describe('web-server', () => {
5756

5857
const injector = new di.Injector([{
5958
config: ['value', config],
60-
customFileHandlers: ['value', customFileHandlers],
6159
emitter: ['value', emitter],
6260
fileList: ['value', { files: { served: [], included: [] } }],
6361
filesPromise: ['factory', m.createFilesPromise],
@@ -182,23 +180,6 @@ describe('web-server', () => {
182180
})
183181
})
184182

185-
it('should load custom handlers', () => {
186-
servedFiles(new Set())
187-
188-
// TODO(vojta): change this, only keeping because karma-dart is relying on it
189-
customFileHandlers.push({
190-
urlRegex: /\/some\/weird/,
191-
handler (request, response, staticFolder, adapterFolder, baseFolder, urlRoot) {
192-
response.writeHead(222)
193-
response.end('CONTENT')
194-
}
195-
})
196-
197-
return request(server)
198-
.get('/some/weird/url')
199-
.expect(222, 'CONTENT')
200-
})
201-
202183
it('should serve 404 for non-existing files', () => {
203184
servedFiles(new Set())
204185

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

218-
customFileHandlers = []
219199
emitter = new EventEmitter()
220200

221201
const injector = new di.Injector([{
@@ -226,7 +206,6 @@ describe('web-server', () => {
226206
httpsServerOptions: credentials,
227207
client: { useIframe: true, useSingleWindow: false }
228208
}],
229-
customFileHandlers: ['value', customFileHandlers],
230209
emitter: ['value', emitter],
231210
fileList: ['value', { files: { served: [], included: [] } }],
232211
filesPromise: ['factory', m.createFilesPromise],
@@ -265,12 +244,10 @@ describe('web-server', () => {
265244
cert: fs.readFileSync(path.join(__dirname, '/certificates/server.crt'))
266245
}
267246

268-
customFileHandlers = []
269247
emitter = new EventEmitter()
270248

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

0 commit comments

Comments
 (0)
Please sign in to comment.