瀏覽代碼

Update tests to use new page config

Steven Silvester 8 年之前
父節點
當前提交
affe14c0da

+ 23 - 15
packages/coreutils/src/pageconfig.ts

@@ -16,7 +16,6 @@ import {
 /**
  * Declare stubs for the node variables.
  */
-declare var global: any;
 declare var process: any;
 declare var require: any;
 
@@ -48,25 +47,32 @@ namespace PageConfig {
       return configData[name] || '';
     }
     configData = Object.create(null);
-    // Use CLI if on node.
-    if (typeof window === 'undefined') {
-      let cli = minimist(process.argv.slice(2));
-      if ('jupyter-config-data' in cli) {
-        let path: any = require('path');
-        let fullPath = path.resolve(cli['jupyter-config-data']);
-        try {
-          configData = global.require(fullPath) as { [key: string]: string };
-        } catch (e) {
-          console.error(e);
-        }
-      }
-    // Use script tag if in the browser.
-    } else {
+    let found = false;
+
+    // Use script tag if available.
+    if (typeof document !== 'undefined') {
       let el = document.getElementById('jupyter-config-data');
       if (el) {
         configData = JSON.parse(el.textContent || '') as { [key: string]: string };
+        console.log('\n\n\n******ho');
+        found = true;
       }
     }
+    // Otherwise use CLI if given.
+    if (!found && typeof process !== 'undefined') {
+      try {
+        let cli = minimist(process.argv.slice(2));
+        if ('jupyter-config-data' in cli) {
+          let path: any = require('path');
+          let fullPath = path.resolve(cli['jupyter-config-data']);
+          // Force Webpack to ignore this require.
+          configData = eval('require')(fullPath) as { [key: string]: string };
+        }
+      } catch (e) {
+        console.error(e);
+      }
+    }
+
     if (!JSONExt.isObject(configData)) {
       configData = Object.create(null);
     } else {
@@ -74,6 +80,8 @@ namespace PageConfig {
         configData[key] = String(configData[key]);
       }
     }
+    console.log('\n\n\n******');
+    console.log(JSON.stringify(configData, null, 2));
     return configData[name] || '';
   }
 

+ 4 - 4
packages/services/package.json

@@ -40,11 +40,11 @@
     "example:browser": "cd examples/browser && npm run update && npm run build",
     "example:node": "cd examples/node && npm install",
     "build:examples": "npm run example:browser && npm run example:node",
-    "test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js test/build*.spec.js --foo bar --terminalsAvailable True",
+    "test:coverage": "istanbul cover --dir test/coverage _mocha -- --retries 3 test/build/**/*.spec.js test/build/*.spec.js --jupyter-config-data=./test/config.json",
     "test:integration": "cd test && python integration_test.py",
-    "test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/*.spec.js test/build/**/*.spec.js --foo bar --terminalsAvailable True",
-    "test:debug": "mocha test/build/**/*.spec.js test/build*.spec.js --foo bar --terminalsAvailable True --debug-brk",
-    "test": "mocha --retries 3 test/build/**.spec.js test/build/**/*.spec.js --foo bar --terminalsAvailable True"
+    "test:devtool": "devtool node_modules/.bin/_mocha -qc test/build/**/*.spec.js test/build*.spec.js --jupyter-config-data=./test/config.json",
+    "test:debug": "mocha test/build/**/*.spec.js test/build*.spec.js  --jupyter-config-data=./test/config.json --debug-brk",
+    "test": "mocha --retries 3 test/build/**/*.spec.js test/build*.spec.js --jupyter-config-data=./test/config.json"
   },
   "repository": {
     "type": "git",

+ 1 - 1
packages/services/src/terminal/default.ts

@@ -268,7 +268,7 @@ namespace DefaultTerminalSession {
       throw Private.unavailableMsg;
     }
     let baseUrl = options.baseUrl || PageConfig.getBaseUrl();
-    let url = baseUrl || PageConfig.getBaseUrl();
+    let url = Private.getBaseUrl(baseUrl);
     let ajaxSettings = utils.ajaxSettingsWithToken(options.ajaxSettings, options.token);
     ajaxSettings.method = 'POST';
     ajaxSettings.dataType = 'json';

+ 4 - 0
packages/services/test/config.json

@@ -0,0 +1,4 @@
+{
+    "foo": "bar",
+    "terminalsAvailable": "True"
+}