Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
export NODE_ENV to browser, add config.IN_TEST_SUITE.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Mar 26, 2015
1 parent 3a8053c commit e6c5ad9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ string), the boolean is true; otherwise, it's false.

Name | Description
------------------|---------------------------------------------
`NODE_ENV` | set this to `production` to automatically minify code and remove various development-only affordances.
`WEBPACK_DEVTOOL` | determines the setting for the [`devtool`][] Webpack option. It defaults to `source-map`; if you're on Firefox, though, you may want to set it to `eval` so that console logging statements originate from useful line numbers. For re details on the trade-offs between different options for development, see our [conversation on sourcemaps][sourcemaps-wtf].
`LESS_AUTOPREFIXER` | set this to `off` to disable the LESS autoprefixer and enable useful CSS source maps, which is a workaround for [#413][].
`AWS_ACCESS_KEY` | is the Amazon Web Services access key used when uploading to s3 via `npm run s3`.
Expand Down
3 changes: 2 additions & 1 deletion components/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var React = require('react');
var Router = require('react-router');
var Link = Router.Link;

var config = require('../lib/config');
var TeachAPIClientMixin = require('../mixins/teach-api-client');
var ga = require('../lib/googleanalytics.js');

Expand Down Expand Up @@ -43,7 +44,7 @@ var Login = React.createClass({
handleApiLoginError: function(err) {
this.setState({loggingIn: false});

if (process.env.NODE_ENV != "test") {
if (!config.IN_TEST_SUITE) {
console.log("Teach API error", err);
ga.event({ category: 'Login', action: 'Teach API Error',
nonInteraction:true});
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ var ENABLE_PUSHSTATE = (IN_STATIC_SITE &&
exports.IN_STATIC_SITE = IN_STATIC_SITE;
exports.GENERATING_STATIC_SITE = GENERATING_STATIC_SITE;
exports.ENABLE_PUSHSTATE = ENABLE_PUSHSTATE;
exports.IN_TEST_SUITE = (typeof describe == 'function');
4 changes: 4 additions & 0 deletions test/browser/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var should = require('should');
var config = require('../../lib/config');

describe('config', function() {
it('should think it is in a test suite', function() {
config.IN_TEST_SUITE.should.be.true;
});

it('should think it is in the browser', function() {
config.IN_STATIC_SITE.should.be.true;
config.GENERATING_STATIC_SITE.should.be.false;
Expand Down
13 changes: 12 additions & 1 deletion test/browser/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
process.env.NODE_ENV = 'test';
var originalConsoleWarn = console.warn;

console.warn = function(msg) {
if (msg == "Warning: You should not use a static location in a " +
"DOM environment because the router will not be kept " +
"in sync with the current URL") {
/* This is a warning react-router emits, which is irrelevant to
* testing scenarios, so we'll squelch it. */
} else {
originalConsoleWarn.apply(this, arguments);
}
};

require('./config.test.js');
require('./page.test.jsx');
Expand Down
4 changes: 4 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var should = require('should');
var config = require('../lib/config');

describe('config', function() {
it('should think it is in a test suite', function() {
config.IN_TEST_SUITE.should.be.true;
});

it('should think it is not in the browser', function() {
config.IN_STATIC_SITE.should.be.false;
config.GENERATING_STATIC_SITE.should.be.true;
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
},
plugins: [
new webpack.DefinePlugin(importEnvVars([
'NODE_ENV',
'TEACH_API_URL',
'GA_ACCOUNT',
'MAPBOX_ACCESS_TOKEN',
Expand Down

0 comments on commit e6c5ad9

Please sign in to comment.