Skip to content

Commit a6d39e6

Browse files
committed
fix: Remote Debug tools do not work - fixes #1556
1 parent f89aa04 commit a6d39e6

6 files changed

Lines changed: 98 additions & 58 deletions

File tree

crossbow.yaml

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,12 @@ tasks:
1313

1414
test:
1515
- build-all
16-
- cypress:*
16+
- bs:*
1717
- cli:*
18+
- unit
1819

19-
(cypress):
20-
file-watching-ignore: >
21-
@npm node cypress/setup/run.js
22-
'../configs/file-watching-ignore.js'
23-
cypress/integration/file-watching-ignore.js
24-
file-reloading: >
25-
@npm node cypress/setup/run.js
26-
'../configs/file-reloading.js'
27-
cypress/integration/file-reloading.js
28-
no-notify: >
29-
@npm node cypress/setup/run.js
30-
'../configs/no-notify.js'
31-
cypress/integration/no-notify.js
32-
css-overlay: >
33-
@npm node cypress/setup/run.js
34-
'../configs/css-overlay-notify.js'
35-
cypress/integration/css-overlay-notify.js
36-
css-console-notify: >
37-
@npm node cypress/setup/run.js
38-
'../configs/css-console-notify.js'
39-
cypress/integration/css-console-notify.js
40-
connection-notify: >
41-
@npm node cypress/setup/run.js
42-
'../configs/file-reloading.js'
43-
cypress/integration/connection-notify.js
44-
log-prefix: >
45-
@npm node cypress/setup/run.js
46-
'../configs/logPrefix.js'
47-
cypress/integration/logPrefix.js
20+
unit: >
21+
@npm mocha --recursive test/specs --timeout 10000 --bail
4822
4923
build-server:
5024
- '@npm tsc'
@@ -68,10 +42,39 @@ tasks:
6842
--write --tab-width 4
6943
7044
cli: cypress/setup/bs-cli.js
45+
bs: cypress/setup/bs.js
7146

7247
options:
48+
bs:
49+
_default:
50+
action: run
51+
file-watching-ignore:
52+
config: cypress/configs/file-watching-ignore.js
53+
spec: cypress/integration/file-watching-ignore.js
54+
file-reloading:
55+
config: cypress/configs/file-reloading.js
56+
spec: cypress/integration/file-reloading.js
57+
no-notify:
58+
config: cypress/configs/no-notify.js
59+
spec: cypress/integration/no-notify.js
60+
css-overlay:
61+
config: cypress/configs/css-overlay-notify.js
62+
spec: cypress/integration/css-overlay-notify.js
63+
css-console-notify:
64+
config: cypress/configs/css-console-notify.js
65+
spec: cypress/integration/css-console-notify.js
66+
connection-notify:
67+
config: cypress/configs/file-reloading.js
68+
spec: cypress/integration/connection-notify.js
69+
log-prefix:
70+
config: cypress/configs/logPrefix.js
71+
spec: cypress/integration/logPrefix.js
72+
ui-remote-debug:
73+
config: cypress/configs/file-reloading.js
74+
spec: cypress/integration/ui-remote-debug.js
75+
7376
cli:
7477
file-watching-ignore:
7578
method: 'run'
7679
args: ['test/fixtures', '--files', 'test/fixtures', '--no-open', '--json']
77-
spec: 'cypress/integration/file-watching-ignore.js'
80+
spec: 'cypress/integration/file-watching-ignore.js'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
describe('UI', function () {
2+
context('Remote Debugger', function () {
3+
it('adds an element, in the way the UI does', function () {
4+
cy.visit(Cypress.env('BS_URL'));
5+
cy.get('#__bs_notify__').should('have.length', 1);
6+
cy.request('POST', `${Cypress.env('BS_URL')}/__browser_sync__`,
7+
JSON.stringify(["ui:element:add",
8+
{
9+
"src": "/browser-sync/pesticide.css",
10+
"active": true,
11+
"hidden": "",
12+
"name": "pesticide",
13+
"tagline": "Add simple CSS outlines to all elements. (powered by <a href=\"http://pesticide.io\" target=\"_blank\">Pesticide.io</a>)",
14+
"context": "remote-debug",
15+
"served": true,
16+
"title": "CSS Outlining",
17+
"type": "css",
18+
"id": "__browser-sync-pesticide__",
19+
"file": "/Users/shakyshane/sites/oss/browser-sync/node_modules/browser-sync-ui/lib/plugins/remote-debug/css/pesticide.min.css"
20+
}
21+
])
22+
).then(res => {
23+
console.log(res);
24+
});
25+
cy.get('[id="__browser-sync-pesticide__"]').should('have.length', 1);
26+
});
27+
});
28+
});

cypress/setup/bs.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
module.exports = function(setup, specs) {
1+
const cypress = require('cypress');
2+
const exec = require('child_process');
3+
const assert = require('assert');
4+
const {join} = require('path');
5+
const {Observable} = require('rxjs/Observable');
26

3-
const cypress = require('cypress');
4-
const bs = require('../../').create();
7+
module.exports = function(opts, ctx) {
58

6-
bs.init(setup, function(err, bs) {
7-
return cypress.run({
8-
spec: specs,
9-
env: `BS_URL=${bs.options.getIn(['urls', 'local'])}`
10-
})
11-
.then((results) => {
12-
// stop your server when it's complete
13-
bs.cleanup();
14-
if (results.failures > 0) {
15-
return process.exit(1);
16-
}
17-
process.exit(0);
9+
assert.ok(typeof opts.config === 'string', '`opts.config` should be a string');
10+
assert.ok(typeof opts.spec === 'string', '`opts.spec` should be a string');
11+
assert.ok((opts.action === 'run' || opts.action === 'open'), '`action` should be either run or open');
12+
13+
const json = require(join(ctx.config.cwd, opts.config));
14+
15+
return Observable.create(obs => {
16+
const bs = require('../../').create();
17+
const instance = bs.init(json, function(err, bs) {
18+
if (err) {
19+
return obs.error(err);
20+
}
21+
return cypress[opts.action]({
22+
spec: opts.spec,
23+
env: `BS_URL=${bs.options.getIn(['urls', 'local'])},BS_UI_URL=${bs.options.getIn(['urls', 'ui'])}`
1824
})
25+
.then((results) => {
26+
// stop your server when it's complete
27+
if (results.failures > 0) {
28+
return obs.error(new Error('Errors occurred'));
29+
}
30+
instance.cleanup();
31+
obs.complete();
32+
})
33+
});
1934
});
2035
};

cypress/setup/run.js

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

lib/hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ module.exports = {
1414
var js = snippetUtils.getClientJs(data.port, data.options);
1515

1616
return hooks.reduce(function(acc, hook) {
17-
return acc.concat(hook);
17+
if (typeof hook === "function") {
18+
return acc.concat(hook);
19+
}
20+
return acc.concat(String(hook));
1821
}, [js]);
1922
},
2023
/**

lib/http-protocol.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ proto.middleware = function(bs) {
6161
}
6262
try {
6363
const [name, payload] = JSON.parse(body.toString());
64-
if (permittedSocketEvents.indexOf(name) > -1) {
65-
bs.io.sockets.emit(name, payload);
66-
return res.end(`Browsersync HTTP Protocol received: ${name} ${JSON.stringify(payload)}`);
67-
} else {
68-
return res.end(`Browsersync HTTP Protocol name not supported: ${name}`);
69-
}
64+
bs.io.sockets.emit(name, payload);
65+
return res.end(`Browsersync HTTP Protocol received: ${name} ${JSON.stringify(payload)}`);
7066
} catch (e) {
7167
const output = [
7268
`Error: ${e.message}`,

0 commit comments

Comments
 (0)