This is solved with shadow DOM.
> In Javascript it seems normal to (at least in angular) push to global scope, and so it can be really unclear where values come from, or how they get set.
Well, nobody forces you to do it in JavaScript. I think newer frameworks (and culture around them) discourages this.
> Testing any of this stuff is also pretty nightmarish. Knowing the web I'm almost certainly behind the curve and there is new hotness out to solve this, but I've never much luck with automated browser testing. Things like Protractor tests are incredibly onerous to write, and inevitably end up as flakey slow messes that fail builds due to flake more often than they find issues.
I agree that testing the whole application is tricky, but testing components is easy enough these days.