jasmine
Advanced tools
Comparing version 4.4.0 to 4.5.0
#!/usr/bin/env node | ||
const path = require('path'); | ||
const os = require('os'); | ||
const Command = require('../lib/command'); | ||
const Jasmine = require('../lib/jasmine'); | ||
const jasmine = new Jasmine({ projectBaseDir: path.resolve() }); | ||
let projectBaseDir = path.resolve(); | ||
if (os.platform() === 'win32') { | ||
// Future versions of glob will interpret backslashes as escape sequences on | ||
// all platforms, and Jasmine warns about them. Convert to slashes to avoid | ||
// the warning and future behavior change. | ||
projectBaseDir = projectBaseDir.replace(/\\/g, '/'); | ||
} | ||
const jasmine = new Jasmine({ projectBaseDir }); | ||
const examplesDir = path.join(path.dirname(require.resolve('jasmine-core')), 'jasmine-core', 'example', 'node_example'); | ||
const command = new Command(path.resolve(), examplesDir, console.log); | ||
const command = new Command(path.resolve(), examplesDir, { | ||
print: console.log, | ||
platform: os.platform, | ||
}); | ||
command.run(jasmine, process.argv.slice(2)); |
@@ -27,6 +27,9 @@ const path = require('path'); | ||
function Command(projectBaseDir, examplesDir, print) { | ||
this.projectBaseDir = projectBaseDir; | ||
this.specDir = path.join(projectBaseDir, 'spec'); | ||
function Command(projectBaseDir, examplesDir, deps) { | ||
const {print, platform} = deps; | ||
const isWindows = platform() === 'win32'; | ||
this.projectBaseDir = isWindows ? unWindows(projectBaseDir) : projectBaseDir; | ||
this.specDir = `${this.projectBaseDir}/spec`; | ||
const command = this; | ||
@@ -50,3 +53,3 @@ | ||
} else { | ||
const env = parseOptions(commands); | ||
const env = parseOptions(commands, isWindows); | ||
if (env.unknownOptions.length > 0) { | ||
@@ -68,3 +71,3 @@ process.exitCode = 1; | ||
function parseOptions(argv) { | ||
function parseOptions(argv, isWindows) { | ||
let files = [], | ||
@@ -106,3 +109,3 @@ helpers = [], | ||
} else if (isFileArg(arg)) { | ||
files.push(arg); | ||
files.push(isWindows ? unWindows(arg) : arg); | ||
} else if (!isEnvironmentVariable(arg)) { | ||
@@ -322,1 +325,9 @@ unknownOptions.push(arg); | ||
} | ||
// Future versions of glob will interpret backslashes as escape sequences on | ||
// all platforms, and Jasmine warns about them. Convert to slashes to avoid | ||
// the warning and future behavior change. Should only be called when running | ||
// on Windows. | ||
function unWindows(projectBaseDir) { | ||
return projectBaseDir.replace(/\\/g, '/'); | ||
} |
@@ -0,1 +1,2 @@ | ||
const os = require('os'); | ||
const path = require('path'); | ||
@@ -45,2 +46,3 @@ const util = require('util'); | ||
this.loader = options.loader || new Loader(); | ||
this.isWindows_ = (options.platform || os.platform)() === 'win32'; | ||
const jasmineCore = options.jasmineCore || require('jasmine-core'); | ||
@@ -54,3 +56,9 @@ | ||
this.projectBaseDir = options.projectBaseDir || path.resolve(); | ||
if (options.projectBaseDir) { | ||
this.validatePath_(options.projectBaseDir); | ||
this.projectBaseDir = options.projectBaseDir; | ||
} else { | ||
this.projectBaseDir = (options.getcwd || path.resolve)(); | ||
} | ||
this.specDir = ''; | ||
@@ -280,2 +288,3 @@ this.specFiles = []; | ||
this.specDir = config.spec_dir || this.specDir; | ||
this.validatePath_(this.specDir); | ||
@@ -317,3 +326,3 @@ /** | ||
* @type boolean | undefined | ||
* @default false | ||
* @default true | ||
*/ | ||
@@ -391,2 +400,20 @@ if (config.alwaysListPendingSpecs !== undefined) { | ||
} | ||
/** | ||
* An array of reporters. Each object in the array will be passed to | ||
* {@link Jasmine#addReporter|addReporter}. | ||
* | ||
* This provides a middle ground between the --reporter= CLI option and full | ||
* programmatic usage. Note that because reporters are objects with methods, | ||
* this option can only be used in JavaScript config files | ||
* (e.g `spec/support/jasmine.js`), not JSON. | ||
* @name Configuration#reporters | ||
* @type Reporter[] | undefined | ||
* @see custom_reporter | ||
*/ | ||
if (config.reporters) { | ||
for (const r of config.reporters) { | ||
this.addReporter(r); | ||
} | ||
} | ||
} | ||
@@ -487,2 +514,12 @@ | ||
} | ||
validatePath_(path) { | ||
if (this.isWindows_ && path.includes('\\')) { | ||
const fixed = path.replace(/\\/g, '/'); | ||
console.warn('Backslashes in ' + | ||
'file paths behave inconsistently between platforms and might not be ' + | ||
'treated as directory separators in a future version. Consider ' + | ||
`changing ${path} to ${fixed}.`); | ||
} | ||
} | ||
} | ||
@@ -511,2 +548,6 @@ | ||
return function (files) { | ||
for (const f of files) { | ||
this.validatePath_(f); | ||
} | ||
const jasmineRunner = this; | ||
@@ -513,0 +554,0 @@ const fileArr = this[kind]; |
@@ -13,3 +13,3 @@ { | ||
"license": "MIT", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"repository": { | ||
@@ -33,3 +33,3 @@ "type": "git", | ||
"glob": "^7.1.6", | ||
"jasmine-core": "^4.4.0" | ||
"jasmine-core": "^4.5.0" | ||
}, | ||
@@ -40,4 +40,2 @@ "bin": "./bin/jasmine.js", | ||
"eslint": "^6.8.0", | ||
"grunt": "^1.0.4", | ||
"grunt-cli": "^1.3.2", | ||
"shelljs": "^0.8.3", | ||
@@ -44,0 +42,0 @@ "slash": "^3.0.0", |
48285
4
1265
Updatedjasmine-core@^4.5.0