testcafe-legacy-api
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -29,2 +29,6 @@ 'use strict'; | ||
var _stripBom = require('strip-bom'); | ||
var _stripBom2 = _interopRequireDefault(_stripBom); | ||
var _crypto = require('crypto'); | ||
@@ -44,6 +48,8 @@ | ||
var _utilsReadSourceFile = require('../utils/read-source-file'); | ||
var _utilsPromisify = require('../utils/promisify'); | ||
var _utilsReadSourceFile2 = _interopRequireDefault(_utilsReadSourceFile); | ||
var _utilsPromisify2 = _interopRequireDefault(_utilsPromisify); | ||
var readFile = _utilsPromisify2.default(fs.readFile); | ||
function exists(filePath) { | ||
@@ -55,8 +61,10 @@ return new _pinkie2.default(function (resolve) { | ||
var FIXTURE_RE = /(^|;|\s+)('|")@fixture\s+.+?\2/gm; | ||
var PAGE_RE = /(^|;|\s+)('|")@page\s+.+?\2/gm; | ||
var TEST_RE = /(^|;|\s+)('|")@test\2\s*\[('|").+?\3\]\s*=\s*\{/gm; | ||
var CompilerAdapter = (function () { | ||
function CompilerAdapter(sources, hammerheadProcessScript) { | ||
function CompilerAdapter(hammerheadProcessScript) { | ||
_classCallCheck(this, CompilerAdapter); | ||
this.sources = sources; | ||
this.cache = { | ||
@@ -129,7 +137,7 @@ requires: {}, | ||
context$2$0.next = 16; | ||
return _regeneratorRuntime.awrap(_utilsReadSourceFile2.default(cfgPath)); | ||
return _regeneratorRuntime.awrap(readFile(cfgPath)); | ||
case 16: | ||
data = context$2$0.sent; | ||
cfg = JSON.parse(data); | ||
cfg = JSON.parse(_stripBom2.default(data)); | ||
@@ -188,27 +196,2 @@ CompilerAdapter._resolveConfigModules(cfg, dir); | ||
CompilerAdapter.prototype.getTests = function getTests() { | ||
var fixtures; | ||
return _regeneratorRuntime.async(function getTests$(context$2$0) { | ||
var _this = this; | ||
while (1) switch (context$2$0.prev = context$2$0.next) { | ||
case 0: | ||
context$2$0.next = 2; | ||
return _regeneratorRuntime.awrap(_pinkie2.default.all(this.sources.map(function (filePath) { | ||
return _this._compileFile(filePath); | ||
}))); | ||
case 2: | ||
fixtures = context$2$0.sent; | ||
return context$2$0.abrupt('return', fixtures.reduce(function (tests, fixture) { | ||
return tests.concat(fixture.tests); | ||
}, [])); | ||
case 4: | ||
case 'end': | ||
return context$2$0.stop(); | ||
} | ||
}, null, this); | ||
}; | ||
CompilerAdapter.prototype._getConfig = function _getConfig(filePath) { | ||
@@ -266,7 +249,7 @@ var dirName, cfg, cachedCfg, dirConfigs; | ||
CompilerAdapter.prototype._createLegacyCompilerPromise = function _createLegacyCompilerPromise(filePath, modules) { | ||
var _this2 = this; | ||
CompilerAdapter.prototype._createLegacyCompilerPromise = function _createLegacyCompilerPromise(code, filename, modules) { | ||
var _this = this; | ||
return new _pinkie2.default(function (resolve, reject) { | ||
var legacyCompiler = new _legacy.Compiler(filePath, modules, _this2.requireReader, _this2.cache.sourceIndex, _this2.hammerheadProcessScript); | ||
var legacyCompiler = new _legacy.Compiler(code, filename, modules, _this.requireReader, _this.cache.sourceIndex, _this.hammerheadProcessScript); | ||
@@ -287,4 +270,4 @@ legacyCompiler.compile(function (errs, out) { | ||
CompilerAdapter.prototype._createFixture = function _createFixture(compiled, filePath, baseUrl, requireJsMapKey, remainderJs) { | ||
var _this3 = this; | ||
CompilerAdapter.prototype._createTests = function _createTests(compiled, filePath, baseUrl, requireJsMapKey, remainderJs) { | ||
var _this2 = this; | ||
@@ -298,26 +281,30 @@ var fixture = { | ||
getSharedJs: function () { | ||
return _this3.cache.requireJsMap[requireJsMapKey] + remainderJs; | ||
return _this2.cache.requireJsMap[requireJsMapKey] + remainderJs; | ||
} | ||
}; | ||
fixture.tests = _Object$keys(compiled.testsStepData).map(function (testName) { | ||
return _Object$keys(compiled.testsStepData).map(function (testName) { | ||
return { | ||
name: testName, | ||
sourceIndex: _this3.cache.sourceIndex, | ||
sourceIndex: _this2.cache.sourceIndex, | ||
stepData: compiled.testsStepData[testName], | ||
fixture: fixture | ||
fixture: fixture, | ||
isLegacy: true | ||
}; | ||
}); | ||
}; | ||
return fixture; | ||
CompilerAdapter.prototype.canCompile = function canCompile(code, filename) { | ||
return (/\.test\.js$/.test(filename) && FIXTURE_RE.test(code) && PAGE_RE.test(code) && TEST_RE.test(code) | ||
); | ||
}; | ||
CompilerAdapter.prototype._compileFile = function _compileFile(filePath) { | ||
CompilerAdapter.prototype.compile = function compile(code, filename) { | ||
var _ref, modules, baseUrl, compiled, hash, requireJsMap, remainderJs, requireJsMapKey; | ||
return _regeneratorRuntime.async(function _compileFile$(context$2$0) { | ||
return _regeneratorRuntime.async(function compile$(context$2$0) { | ||
while (1) switch (context$2$0.prev = context$2$0.next) { | ||
case 0: | ||
context$2$0.next = 2; | ||
return _regeneratorRuntime.awrap(this._getConfig(filePath)); | ||
return _regeneratorRuntime.awrap(this._getConfig(filename)); | ||
@@ -329,3 +316,3 @@ case 2: | ||
context$2$0.next = 7; | ||
return _regeneratorRuntime.awrap(this._createLegacyCompilerPromise(filePath, modules)); | ||
return _regeneratorRuntime.awrap(this._createLegacyCompilerPromise(code, filename, modules)); | ||
@@ -344,3 +331,3 @@ case 7: | ||
return context$2$0.abrupt('return', this._createFixture(compiled, filePath, baseUrl, requireJsMapKey, remainderJs)); | ||
return context$2$0.abrupt('return', this._createTests(compiled, filename, baseUrl, requireJsMapKey, remainderJs)); | ||
@@ -347,0 +334,0 @@ case 15: |
@@ -22,3 +22,3 @@ 'use strict'; | ||
//Call Analyzer | ||
var CallAnalyzer = function (ast, filename, errs, isSharedCode, sourceIndex, src) { | ||
var CallAnalyzer = function CallAnalyzer(ast, filename, errs, isSharedCode, sourceIndex, src) { | ||
this.ast = ast; | ||
@@ -45,3 +45,3 @@ this.src = src; | ||
walker.with_walkers({ | ||
'call': function () { | ||
'call': function call() { | ||
var isDot = Ast.getEntryName(this[1]) === 'dot'; | ||
@@ -48,0 +48,0 @@ |
@@ -15,3 +15,3 @@ 'use strict'; | ||
walker.with_walkers({ | ||
'string': function () { | ||
'string': function string() { | ||
var astPath = walker.stack(), | ||
@@ -18,0 +18,0 @@ topStatement = astPath[1][0]; |
'use strict'; | ||
var util = require('util'), | ||
fs = require('fs'), | ||
javascriptParser = require('uglify-js').parser, | ||
ErrCodes = require('./err_codes'), | ||
readSourceFile = require('../../utils/read-source-file'); | ||
stripBom = require('strip-bom'), | ||
promisify = require('../../utils/promisify'); | ||
var readFile = promisify(fs.readFile); | ||
exports.construct = function (fileName, ownerFilename, callback) { | ||
readSourceFile(fileName).then(function (data) { | ||
var ast = null, | ||
srcCode = data.toString().trim(); | ||
readFile(fileName).then(function (data) { | ||
data = stripBom(data); | ||
//NOTE: perform srcCode preprocessing the same way it's done in the uglify tokenizer, so | ||
//we'll get correct entities positions for code generator | ||
srcCode = srcCode.replace(/\r\n?|[\n\u2028\u2029]/g, "\n"); | ||
var constructed = null; | ||
try { | ||
ast = javascriptParser.parse(srcCode, false, true); | ||
} catch (parseErr) { | ||
callback({ | ||
type: ErrCodes.JAVASCRIPT_PARSING_FAILED, | ||
filename: fileName, | ||
parserErr: parseErr | ||
}); | ||
constructed = constructFromCode(data, fileName); | ||
} catch (err) { | ||
callback(err); | ||
return; | ||
} | ||
callback(null, ast, srcCode); | ||
}).catch(function () { | ||
callback(null, constructed.ast, constructed.preprocessedCode); | ||
})['catch'](function () { | ||
callback({ | ||
@@ -39,2 +35,27 @@ type: ownerFilename ? ErrCodes.FAILED_LOAD_REQUIRE : ErrCodes.READ_FILE_FAILED, | ||
var constructFromCode = exports.constructFromCode = function (code, fileName) { | ||
var ast = null; | ||
code = code.toString().trim(); | ||
//NOTE: perform srcCode preprocessing the same way it's done in the uglify tokenizer, so | ||
//we'll get correct entities positions for code generator | ||
code = code.replace(/\r\n?|[\n\u2028\u2029]/g, "\n"); | ||
try { | ||
ast = javascriptParser.parse(code, false, true); | ||
} catch (parseErr) { | ||
throw { | ||
type: ErrCodes.JAVASCRIPT_PARSING_FAILED, | ||
filename: fileName, | ||
parserErr: parseErr | ||
}; | ||
} | ||
return { | ||
ast: ast, | ||
preprocessedCode: code | ||
}; | ||
}; | ||
var getEntryName = exports.getEntryName = function (entry) { | ||
@@ -41,0 +62,0 @@ return typeof entry[0] === 'object' ? entry[0].name : entry[0]; |
@@ -35,3 +35,3 @@ 'use strict'; | ||
exports.TEST_CASE_INIT_STEP_NAME = '-INIT TEST CASE-'; | ||
exports.TEST_CASE_NAME_SEPARATOR = ' \u2192 '; | ||
exports.TEST_CASE_NAME_SEPARATOR = ' → '; | ||
exports.TEST_CASE_DEFAULT_NAME_PATTERN = 'Test case at index %s'; | ||
@@ -38,0 +38,0 @@ |
'use strict'; | ||
var _Object$defineProperties = require('babel-runtime/core-js/object/define-properties').default; | ||
var _Object$keys = require('babel-runtime/core-js/object/keys').default; | ||
var _Promise = require('babel-runtime/core-js/promise').default; | ||
var path = require('path'), | ||
fs = require('fs'), | ||
util = require('util'), | ||
@@ -14,2 +9,4 @@ astProcessor = require('uglify-js').uglify, | ||
async = require('async'), | ||
stripBom = require('strip-bom'), | ||
Promise = require('pinkie'), | ||
Common = require('./common'), | ||
@@ -20,4 +17,6 @@ Ast = require('./ast'), | ||
ErrCodes = require('./err_codes'), | ||
readSourceFile = require('../../utils/read-source-file'); | ||
promisify = require('../../utils/promisify'); | ||
var readFile = promisify(fs.readFile); | ||
//Util | ||
@@ -32,3 +31,3 @@ //NOTE: this is a version of splice which can operate with array of the injectable items | ||
//Compiler | ||
var Compiler = module.exports = function (filename, modules, requireReader, sourceIndex, hammerheadProcessScript) { | ||
var Compiler = module.exports = function (src, filename, modules, requireReader, sourceIndex, hammerheadProcessScript) { | ||
this.walker = astProcessor.ast_walker(); | ||
@@ -38,3 +37,3 @@ this.hammerheadProcessScript = hammerheadProcessScript; | ||
this.filename = filename; | ||
this.src = null; | ||
this.src = src; | ||
this.workingDir = path.dirname(this.filename); | ||
@@ -72,9 +71,9 @@ | ||
_Object$defineProperties(Compiler.prototype, { | ||
Object.defineProperties(Compiler.prototype, { | ||
ok: { | ||
get: function () { | ||
get: function get() { | ||
return !this.errs.length && this.okFlag; | ||
}, | ||
set: function (value) { | ||
set: function set(value) { | ||
this.okFlag = value; | ||
@@ -194,3 +193,3 @@ } | ||
this.walker.with_walkers({ | ||
'string': function () { | ||
'string': function string() { | ||
var astPath = compiler.walker.stack(), | ||
@@ -234,3 +233,3 @@ topStatement = astPath[1][0]; | ||
_Object$keys(requireDescriptor.rawMixinsStepData).forEach(function (name) { | ||
Object.keys(requireDescriptor.rawMixinsStepData).forEach(function (name) { | ||
if (compiler.rawMixinsStepData[name]) { | ||
@@ -262,3 +261,3 @@ compiler._fixtureErr(ErrCodes.DUPLICATE_MIXIN_NAME_IN_REQUIRE, null, { | ||
_Promise.all(requireReaderPromises).then(function (descriptors) { | ||
Promise.all(requireReaderPromises).then(function (descriptors) { | ||
descriptors.forEach(function (descriptor) { | ||
@@ -341,3 +340,3 @@ _this._mergeRequireMixins(descriptor); | ||
var compiler = this, | ||
testNames = _Object$keys(this.rawTestsStepData); | ||
testNames = Object.keys(this.rawTestsStepData); | ||
@@ -424,3 +423,5 @@ testNames.forEach(function (testName) { | ||
return function (readerCallback) { | ||
readSourceFile(testCasesPath).then(function (data) { | ||
readFile(testCasesPath).then(function (data) { | ||
data = stripBom(data); | ||
var ast = compiler._parseExternalTestCases(data); | ||
@@ -434,3 +435,3 @@ compiler._validateTestCaseListAst(ast, testCasesPath); | ||
readerCallback(); | ||
}).catch(function () { | ||
})['catch'](function () { | ||
compiler._fixtureErr(ErrCodes.FAILED_TO_READ_EXTERNAL_TEST_CASES, 0, { testCasesPath: testCasesPath }); | ||
@@ -447,3 +448,3 @@ readerCallback(); | ||
_Object$keys(this.rawTestsStepData).forEach(function (testName) { | ||
Object.keys(this.rawTestsStepData).forEach(function (testName) { | ||
var testStepData = compiler.rawTestsStepData[testName]; | ||
@@ -469,3 +470,3 @@ | ||
//NOTE: run external test cases analyzers | ||
_Object$keys(externalTestCases).forEach(function (testCasesPath) { | ||
Object.keys(externalTestCases).forEach(function (testCasesPath) { | ||
externalTestCasesAnalyzers.push(compiler._createExternalTestCasesAnalyzer(testCasesPath, externalTestCases[testCasesPath])); | ||
@@ -480,23 +481,29 @@ }); | ||
var compiler = this; | ||
var constructed = null; | ||
Ast.construct(this.filename, null, function (parseErr, ast, src) { | ||
if (parseErr) callback([parseErr]);else { | ||
compiler.src = src; | ||
compiler._analyzeAst(ast); | ||
try { | ||
constructed = Ast.constructFromCode(this.src, this.filename); | ||
} catch (parserErr) { | ||
callback([parserErr]); | ||
return; | ||
} | ||
if (!compiler.out.fixture) compiler._fixtureErr(ErrCodes.FIXTURE_DIRECTIVE_IS_UNDEFINED); | ||
var ast = constructed.ast; | ||
if (!compiler.out.page) compiler._fixtureErr(ErrCodes.PAGE_DIRECTIVE_IS_UNDEFINED); | ||
compiler.src = constructed.preprocessedCode; | ||
compiler._analyzeAst(ast); | ||
compiler.out.remainderJs = compiler._getRemainderCode(ast); | ||
if (!compiler.out.fixture) compiler._fixtureErr(ErrCodes.FIXTURE_DIRECTIVE_IS_UNDEFINED); | ||
compiler._analyzeRequires(function () { | ||
compiler._prepareTestCases(function () { | ||
compiler._compileTestsStepData(); | ||
if (!compiler.out.page) compiler._fixtureErr(ErrCodes.PAGE_DIRECTIVE_IS_UNDEFINED); | ||
if (compiler.ok) callback(null, compiler.out);else callback(compiler.errs); | ||
}); | ||
}); | ||
} | ||
compiler.out.remainderJs = compiler._getRemainderCode(ast); | ||
compiler._analyzeRequires(function () { | ||
compiler._prepareTestCases(function () { | ||
compiler._compileTestsStepData(); | ||
if (compiler.ok) callback(null, compiler.out);else callback(compiler.errs); | ||
}); | ||
}); | ||
}; |
@@ -8,4 +8,6 @@ // -------------------------------------------------------- | ||
exports.__esModule = true; | ||
exports.default = { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports['default'] = { | ||
ACTION_FUNC_NAMES: ['click', 'rclick', 'dblclick', 'drag', 'type', 'wait', 'waitFor', 'hover', 'press', 'select', 'navigateTo', 'upload', 'screenshot'], | ||
@@ -15,2 +17,2 @@ | ||
}; | ||
module.exports = exports.default; | ||
module.exports = exports['default']; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var msg = 'UNKNOWN_ERROR', | ||
m = function () { | ||
m = function m() { | ||
msg = util.format.apply(this, arguments); | ||
@@ -11,0 +11,0 @@ }; |
{ | ||
"name": "testcafe-legacy-api", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Legacy API support for TestCafe", | ||
@@ -34,2 +34,3 @@ "main": "lib/index.js", | ||
"gulp-mocha": "^2.2.0", | ||
"multiline": "^1.0.2", | ||
"publish-please": "^1.1.0", | ||
@@ -45,2 +46,3 @@ "read-file-relative": "^1.2.0", | ||
"pinkie": "^2.0.1", | ||
"strip-bom": "^2.0.0", | ||
"uglify-js": "1.2.6" | ||
@@ -47,0 +49,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
69546
7
13
18
1407
4
+ Addedstrip-bom@^2.0.0
+ Addedis-utf8@0.2.1(transitive)
+ Addedstrip-bom@2.0.0(transitive)