From 52e38d8dd087414438839b957dd351266218f371 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 14 Oct 2016 15:58:22 -0400 Subject: [PATCH] Convert spec-suite to es6 --- spec/jasmine-helper.es6 | 2 + spec/spec-suite.coffee | 70 ----------------------------- spec/spec-suite.es6 | 99 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 70 deletions(-) delete mode 100644 spec/spec-suite.coffee create mode 100644 spec/spec-suite.es6 diff --git a/spec/jasmine-helper.es6 b/spec/jasmine-helper.es6 index d54a975d3..a597b6f58 100644 --- a/spec/jasmine-helper.es6 +++ b/spec/jasmine-helper.es6 @@ -1,3 +1,5 @@ +/* eslint global-require:0 */ + import { remote } from 'electron'; import jasmineExports from './jasmine'; import {TerminalReporter} from 'jasmine-tagged'; diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee deleted file mode 100644 index 5f0ebcedd..000000000 --- a/spec/spec-suite.coffee +++ /dev/null @@ -1,70 +0,0 @@ -_ = require 'underscore' -fs = require 'fs-plus' -path = require 'path' -require './spec-helper' - -requireSpecs = (specDirectory) -> - specFilePattern = NylasEnv.getLoadSettings().specFilePattern - - if _.isString(specFilePattern) and specFilePattern.length > 0 - regex = new RegExp(specFilePattern) - else - regex = /-spec\.(coffee|js|jsx|cjsx|es6|es)$/ - - for specFilePath in fs.listTreeSync(specDirectory) - require(specFilePath) if regex.test(specFilePath) - - # Set spec directory on spec for setting up the project in spec-helper - setSpecDirectory(specDirectory) - -setSpecField = (name, value) -> - specs = jasmine.getEnv().currentRunner().specs() - return if specs.length is 0 - for index in [specs.length-1..0] - break if specs[index][name]? - specs[index][name] = value - -setSpecType = (specType) -> - setSpecField('specType', specType) - -setSpecDirectory = (specDirectory) -> - setSpecField('specDirectory', specDirectory) - -runAllSpecs = -> - {resourcePath} = NylasEnv.getLoadSettings() - - requireSpecs(path.join(resourcePath, 'spec')) - - setSpecType('core') - - fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages') - # packagePaths = NylasEnv.packages.getAvailablePackageNames().map (packageName) -> - # NylasEnv.packages.resolvePackagePath(packageName) - - # EDGEHILL_CORE: Look in internal_packages instead of node_modules - packagePaths = [] - for packagePath in fs.listSync(path.join(resourcePath, "internal_packages")) - packagePaths.push(packagePath) if fs.isDirectorySync(packagePath) - packagePaths = _.uniq packagePaths - - packagePaths = _.groupBy packagePaths, (packagePath) -> - if packagePath.indexOf("#{fixturesPackagesPath}#{path.sep}") is 0 - 'fixtures' - else if packagePath.indexOf("#{resourcePath}#{path.sep}") is 0 - 'bundled' - else - 'user' - - # Run bundled package specs - requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.bundled ? [] - setSpecType('bundled') - - # Run user package specs - requireSpecs(path.join(packagePath, 'spec')) for packagePath in packagePaths.user ? [] - setSpecType('user') - -if specDirectory = NylasEnv.getLoadSettings().specDirectory - requireSpecs(specDirectory) - setSpecType('user') -else - runAllSpecs() diff --git a/spec/spec-suite.es6 b/spec/spec-suite.es6 new file mode 100644 index 000000000..9274b3c97 --- /dev/null +++ b/spec/spec-suite.es6 @@ -0,0 +1,99 @@ +/* eslint global-require:0 */ + +import _ from 'underscore'; +import fs from 'fs-plus'; +import path from 'path'; +import './spec-helper'; + +function setSpecField(name, value) { + const specs = jasmine.getEnv().currentRunner().specs(); + if (specs.length === 0) { return; } + + for (let i = 0; i < specs.length; i++) { + if (specs[i][name]) break; + specs[i][name] = value + } +} + +function setSpecType(specType) { + setSpecField('specType', specType); +} + +function setSpecDirectory(specDirectory) { + setSpecField('specDirectory', specDirectory); +} + +function requireSpecs(specDirectory) { + const { specFilePattern } = NylasEnv.getLoadSettings(); + + let regex = /-spec\.(coffee|js|jsx|cjsx|es6|es)$/; + if (_.isString(specFilePattern) && specFilePattern.length > 0) { + regex = new RegExp(specFilePattern); + } + + for (const specFilePath of fs.listTreeSync(specDirectory)) { + if (regex.test(specFilePath)) { + require(specFilePath) + } + } + + // Set spec directory on spec for setting up the project in + // spec-helper + setSpecDirectory(specDirectory) +} + +function runAllSpecs() { + const {resourcePath} = NylasEnv.getLoadSettings(); + + requireSpecs(path.join(resourcePath, 'spec')); + + setSpecType('core'); + + const fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages'); + + // EDGEHILL_CORE: Look in internal_packages instead of node_modules + let packagePaths = []; + const iterable = fs.listSync(path.join(resourcePath, "internal_packages")); + for (let i = 0; i < iterable.length; i++) { + const packagePath = iterable[i]; + if (fs.isDirectorySync(packagePath)) { + packagePaths.push(packagePath); + } + } + + packagePaths = _.uniq(packagePaths); + + packagePaths = _.groupBy(packagePaths, (packagePath) => { + if (packagePath.indexOf(`${fixturesPackagesPath}${path.sep}`) === 0) { + return 'fixtures'; + } else if (packagePath.indexOf(`${resourcePath}${path.sep}`) === 0) { + return 'bundled'; + } + return 'user'; + }); + + // Run bundled package specs + const iterable1 = packagePaths.bundled != null ? packagePaths.bundled : []; + + for (let j = 0; j < iterable1.length; j++) { + const packagePath = iterable1[j]; + requireSpecs(path.join(packagePath, 'spec')); + } + setSpecType('bundled'); + + // Run user package specs + const iterable2 = packagePaths.user != null ? packagePaths.user : []; + for (let k = 0; k < iterable2.length; k++) { + const packagePath = iterable2[k]; + requireSpecs(path.join(packagePath, 'spec')); + } + return setSpecType('user'); +} + +const specDirectory = NylasEnv.getLoadSettings().specDirectory; +if (specDirectory) { + requireSpecs(specDirectory); + setSpecType('user'); +} else { + runAllSpecs(); +}