From e06314520af6c0444d14653017e28474b118d11f Mon Sep 17 00:00:00 2001 From: Sushant Date: Sat, 2 Jun 2018 11:08:49 +0530 Subject: [PATCH 1/5] chores: update dependencies / use windows in ci --- .eslintignore | 2 ++ .eslintrc.json | 11 ++++---- appveyor-setup.ps1 | 42 ++++++++++++++++++++++++++++++ appveyor.yml | 33 ++++++++++++++++++++++++ package.json | 31 ++++++++++------------ test/support/config/config.js | 48 ++++++++++++++++++++++------------- test/support/index.js | 8 +++++- 7 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 .eslintignore create mode 100644 appveyor-setup.ps1 create mode 100644 appveyor.yml diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..1ff7fd216 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +test/support +src/assets \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 6a1e03212..cf7e18b77 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,8 +3,8 @@ "no-console": "off", "no-extra-parens": "warn", "valid-jsdoc": "off", - "new-cap": ["warn", {"properties": false}], - "comma-spacing": ["error", {"before": false, "after": true}], + "new-cap": ["warn", { "properties": false }], + "comma-spacing": ["error", { "before": false, "after": true }], "no-extra-boolean-cast": "warn", "strict": ["warn", "global"], "no-var": "error", @@ -21,14 +21,14 @@ "eqeqeq": "error", "no-extend-native": "error", "wrap-iife": ["error", "any"], - "indent": ["error", 2, {"SwitchCase": 1}], + "indent": ["error", 2, { "SwitchCase": 1 }], "no-use-before-define": "off", "no-caller": "error", "no-undef": "error", "no-unused-vars": "error", "no-irregular-whitespace": "error", "max-depth": ["error", 8], - "quotes": ["error", "single", {"avoidEscape": true}], + "quotes": ["error", "single", { "avoidEscape": true }], "linebreak-style": "error", "no-loop-func": "warn", "object-shorthand": "error", @@ -45,5 +45,6 @@ "node": true, "mocha": true, "es6": true - } + }, + "root": true } diff --git a/appveyor-setup.ps1 b/appveyor-setup.ps1 new file mode 100644 index 000000000..0c8bfc515 --- /dev/null +++ b/appveyor-setup.ps1 @@ -0,0 +1,42 @@ + +Set-Service sqlbrowser -StartupType auto +Start-Service sqlbrowser + +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null + +$wmi = New-Object('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer') +$tcp = $wmi.GetSmoObject("ManagedComputer[@Name='${env:computername}']/ServerInstance[@Name='SQL2017']/ServerProtocol[@Name='Tcp']") +$tcp.IsEnabled = $true +$tcp.Alter() + +$wmi = New-Object('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer') +$ipall = $wmi.GetSmoObject("ManagedComputer[@Name='${env:computername}']/ServerInstance[@Name='SQL2017']/ServerProtocol[@Name='Tcp']/IPAddress[@Name='IPAll']") +$port = $ipall.IPAddressProperties.Item("TcpDynamicPorts").Value + +$config = @{ + instanceName = "SQL2017" + host = "localhost" + username = "sa" + password = "Password12!" + port = $port + database = "sequelize_test" + dialectOptions = @{ + requestTimeout = 25000 + cryptoCredentialsDetails = @{ + ciphers = "RC4-MD5" + } + } + pool = @{ + max = 5 + idle = 3000 + } +} + +$json = $config | ConvertTo-Json -Depth 3 + +# Create sequelize_test database +sqlcmd -S "(local)" -U "sa" -P "Password12!" -d "master" -Q "CREATE DATABASE [sequelize_test]; ALTER DATABASE [sequelize_test] SET READ_COMMITTED_SNAPSHOT ON;" + +# cannot use Out-File because it outputs a BOM +[IO.File]::WriteAllLines((Join-Path $pwd "test\support\config\mssql.json"), $json) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..6319e40b1 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,33 @@ +version: '{build}' + +platform: + - x64 + +services: + - mssql2017 + +shallow_clone: true + +build: off + +matrix: + fast_finish: true + +environment: + matrix: + - { NODE_VERSION: 6, DIALECT: mssql } + +install: + - ps: Install-Product node $env:NODE_VERSION x64 + - "set PATH=%APPVEYOR_BUILD_FOLDER%\\lib;%PATH%" + - ps: | + $pkg = ConvertFrom-Json (Get-Content -Raw package.json) + $pkg.devDependencies.PSObject.Properties.Remove('sqlite3') + ConvertTo-Json $pkg | Out-File package.json -Encoding UTF8 + - npm install + +before_test: + - ps: . .\appveyor-setup.ps1 + +test_script: + - 'npm run test' \ No newline at end of file diff --git a/package.json b/package.json index 8486a5cf9..8193e253c 100644 --- a/package.json +++ b/package.json @@ -10,43 +10,40 @@ "cli-color": "^1.2.0", "fs-extra": "^5.0.0", "js-beautify": "^1.7.4", - "lodash": "^4.17.5", - "resolve": "^1.5.0", + "lodash": "^4.17.10", + "resolve": "^1.7.1", "umzug": "^2.1.0", "yargs": "^8.0.2" }, + "peerDependencies": { + "sequelize": "=3 || =4" + }, "devDependencies": { "babel-cli": "^6.24.1", "babel-plugin-transform-async-to-module-method": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.23.0", - "babel-preset-env": "^1.6.1", + "babel-preset-env": "^1.7.0", "babel-register": "^6.24.1", - "eslint": "^4.11.0", + "eslint": "^4.19.1", "expect.js": "^0.3.1", "gulp": "^3.9.1", "mocha": "^3.5.0", "mysql": "^2.15.0", "nodeify": "^1.0.1", - "pg": "^7.*", + "pg": "^7.4.3", "pg-hstore": "^2.x", - "sequelize": "^4.x", - "sqlite3": "^3.x", + "sequelize": "^4.37.10", + "sqlite3": "^4.0.0", + "tedious": "^2.6.1", "through2": "^2.0.3" }, - "options": { - "mocha": "--require scripts/mocha-bootload.js --check-leaks --timeout 30000 --colors --reporter spec" - }, - "eslintIgnore": [ - "test/support", - "src/assets" - ], "scripts": { "build": "npm run build-clean && babel src -d lib && npm run build-bin && npm run build-assets", - "build-bin": "mv ./lib/sequelize.js ./lib/sequelize && chmod +x ./lib/sequelize", + "build-bin": "cp ./lib/sequelize.js ./lib/sequelize && chmod +x ./lib/sequelize ./lib/sequelize.js", "build-assets": "cp -R ./src/assets ./lib/", "build-clean": "rm -rf ./lib/", - "lint": "eslint test src", - "test-raw": "mocha $npm_package_options_mocha 'test/**/*.test.js'", + "lint": "eslint test src --quiet", + "test-raw": "mocha --require scripts/mocha-bootload.js --check-leaks --timeout 30000 --colors --reporter spec test/**/*.test.js", "test": "npm run lint && npm run build && npm run test-raw" }, "repository": { diff --git a/test/support/config/config.js b/test/support/config/config.js index 6185ee72e..31c806362 100644 --- a/test/support/config/config.js +++ b/test/support/config/config.js @@ -1,13 +1,21 @@ 'use strict'; +const fs = require('fs'); +let mssqlConfig; +try { + mssqlConfig = JSON.parse(fs.readFileSync(__dirname + '/mssql.json', 'utf8')); +} catch (e) { + // ignore +} + module.exports = { username: process.env.SEQ_USER || 'root', password: process.env.SEQ_PW || null, database: process.env.SEQ_DB || 'sequelize_test', host: process.env.SEQ_HOST || '127.0.0.1', pool: { - maxConnections: process.env.SEQ_POOL_MAX || 5, - maxIdleTime: process.env.SEQ_POOL_IDLE || 30000 + max: process.env.SEQ_POOL_MAX || 5, + idle: process.env.SEQ_POOL_IDLE || 30000 }, rand: function () { @@ -22,8 +30,24 @@ module.exports = { host: process.env.SEQ_MYSQL_HOST || process.env.SEQ_HOST || '127.0.0.1', port: process.env.SEQ_MYSQL_PORT || process.env.SEQ_PORT || 3306, pool: { - maxConnections: process.env.SEQ_MYSQL_POOL_MAX || process.env.SEQ_POOL_MAX || 5, - maxIdleTime: process.env.SEQ_MYSQL_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 + max: process.env.SEQ_MYSQL_POOL_MAX || process.env.SEQ_POOL_MAX || 5, + idle: process.env.SEQ_MYSQL_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 + } + }, + + mssql: mssqlConfig || { + database: process.env.SEQ_MSSQL_DB || process.env.SEQ_DB || 'sequelize_test', + username: process.env.SEQ_MSSQL_USER || process.env.SEQ_USER || 'sequelize', + password: process.env.SEQ_MSSQL_PW || process.env.SEQ_PW || 'nEGkLma26gXVHFUAHJxcmsrK', + host: process.env.SEQ_MSSQL_HOST || process.env.SEQ_HOST || '127.0.0.1', + port: process.env.SEQ_MSSQL_PORT || process.env.SEQ_PORT || 1433, + dialectOptions: { + // big insert queries need a while + requestTimeout: 60000 + }, + pool: { + max: process.env.SEQ_MSSQL_POOL_MAX || process.env.SEQ_POOL_MAX || 5, + idle: process.env.SEQ_MSSQL_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 } }, @@ -37,20 +61,8 @@ module.exports = { host: process.env.SEQ_PG_HOST || process.env.SEQ_HOST || '127.0.0.1', port: process.env.SEQ_PG_PORT || process.env.SEQ_PORT || 5432, pool: { - maxConnections: process.env.SEQ_PG_POOL_MAX || process.env.SEQ_POOL_MAX || 5, - maxIdleTime: process.env.SEQ_PG_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 - } - }, - - mariadb: { - database: process.env.SEQ_MYSQL_DB || process.env.SEQ_DB || 'sequelize_test', - username: process.env.SEQ_MYSQL_USER || process.env.SEQ_USER || 'root', - password: process.env.SEQ_MYSQL_PW || process.env.SEQ_PW || null, - host: process.env.SEQ_MYSQL_HOST || process.env.SEQ_HOST || '127.0.0.1', - port: process.env.SEQ_MYSQL_PORT || process.env.SEQ_PORT || 3306, - pool: { - maxConnections: process.env.SEQ_MYSQL_POOL_MAX || process.env.SEQ_POOL_MAX || 5, - maxIdleTime: process.env.SEQ_MYSQL_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 + max: process.env.SEQ_PG_POOL_MAX || process.env.SEQ_POOL_MAX || 5, + idle: process.env.SEQ_PG_POOL_IDLE || process.env.SEQ_POOL_IDLE || 3000 } } }; diff --git a/test/support/index.js b/test/support/index.js index eec4f46fa..a1d44a92a 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -197,7 +197,13 @@ var Support = { }, getCliCommand: function (cwd, flags) { - return this.getCliPath(cwd) + ' ' + flags; + var command = this.getCliPath(cwd) + ' ' + flags; + + if (process.platform.startsWith('win')) { + return `node ${command}`; + } + + return command; }, getSupportDirectoryPath: function () { From 503966c92fe781e502dbf057ec373547b73d52bf Mon Sep 17 00:00:00 2001 From: Sushant Date: Sun, 3 Jun 2018 16:36:34 +0530 Subject: [PATCH 2/5] fix(readTables): fix for mssql nonstandard return --- test/support/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/helpers.js b/test/support/helpers.js index 8454065ac..9d5e885b5 100644 --- a/test/support/helpers.js +++ b/test/support/helpers.js @@ -178,7 +178,7 @@ module.exports = { .getQueryInterface() .showAllTables() .then(function (tables) { - return callback(tables.sort()); + return callback(tables.map(tableName => tableName.tableName || tableName).sort()); }); }, From 51bc832ec31bb9e940d6b1fd83f3fc398f920aff Mon Sep 17 00:00:00 2001 From: Sushant Date: Sun, 3 Jun 2018 17:12:25 +0530 Subject: [PATCH 3/5] fix(mssql): showAllTable non-standard return --- src/core/migrator.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/migrator.js b/src/core/migrator.js index c8f2803d6..461124a2a 100644 --- a/src/core/migrator.js +++ b/src/core/migrator.js @@ -87,6 +87,7 @@ export function ensureCurrentMetaSchema (migrator) { function ensureMetaTable (queryInterface, tableName) { return queryInterface.showAllTables() .then(tableNames => { + tableNames = tableNames.map(tableName => tableName.tableName || tableName); // MSSQL if (tableNames.indexOf(tableName) === -1) { throw new Error('No MetaTable table found.'); } From 765e32b4566d5704d05bd38d508f5061853c04c7 Mon Sep 17 00:00:00 2001 From: Sushant Date: Sun, 3 Jun 2018 17:43:20 +0530 Subject: [PATCH 4/5] assert widndows based path --- .travis.yml | 2 -- package.json | 2 +- test/init.test.js | 12 ++++++++++-- test/support/index.js | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4088a455..f17a5497c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,8 @@ cache: jobs: include: - - stage: tests node_js: 4 env: DIALECT=postgres SEQUELIZE=latest - - stage: tests node_js: 4 env: DIALECT=sqlite SEQUELIZE=latest diff --git a/package.json b/package.json index 8193e253c..336a2847c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "yargs": "^8.0.2" }, "peerDependencies": { - "sequelize": "=3 || =4" + "sequelize": "=3 || =4 || =5" }, "devDependencies": { "babel-cli": "^6.24.1", diff --git a/test/init.test.js b/test/init.test.js index 5636b4c6e..078735155 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -86,6 +86,10 @@ const gulp = require('gulp'); describe('models/index.js', () => { it('correctly injects the reference to the default config file', done => { + let path = Support.isWindows() + ? '__dirname + \'/..\\config\\config.json\'' + : '__dirname + \'/../config/config.json\''; + gulp .src(Support.resolveSupportPath('tmp')) .pipe(helpers.clearDirectory()) @@ -94,12 +98,16 @@ const gulp = require('gulp'); gulp .src(Support.resolveSupportPath('tmp', 'models')) .pipe(helpers.readFile('index.js')) - .pipe(helpers.ensureContent('__dirname + \'/../config/config.json\'')) + .pipe(helpers.ensureContent(path)) .pipe(helpers.teardown(done)); })); }); it('correctly injects the reference to the custom config file', done => { + let path = Support.isWindows() + ? '__dirname + \'/..\\my\\configuration-file.json\'' + : '__dirname + \'/../my/configuration-file.json\''; + gulp .src(Support.resolveSupportPath('tmp')) .pipe(helpers.clearDirectory()) @@ -108,7 +116,7 @@ const gulp = require('gulp'); gulp .src(Support.resolveSupportPath('tmp', 'models')) .pipe(helpers.readFile('index.js')) - .pipe(helpers.ensureContent('__dirname + \'/../my/configuration-file.json\'')) + .pipe(helpers.ensureContent(path)) .pipe(helpers.teardown(done)); })); }); diff --git a/test/support/index.js b/test/support/index.js index a1d44a92a..6f27fa887 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -199,13 +199,17 @@ var Support = { getCliCommand: function (cwd, flags) { var command = this.getCliPath(cwd) + ' ' + flags; - if (process.platform.startsWith('win')) { + if (this.isWindows()) { return `node ${command}`; } return command; }, + isWindows() { + return process.platform.startsWith('win'); + }, + getSupportDirectoryPath: function () { return path.resolve(__dirname); }, From 28e0ae8d1b23afc5bf8493d560926c668f899a2f Mon Sep 17 00:00:00 2001 From: Sushant Date: Sun, 3 Jun 2018 17:46:14 +0530 Subject: [PATCH 5/5] lint --- test/init.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/init.test.js b/test/init.test.js index 078735155..612935cee 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -86,9 +86,9 @@ const gulp = require('gulp'); describe('models/index.js', () => { it('correctly injects the reference to the default config file', done => { - let path = Support.isWindows() - ? '__dirname + \'/..\\config\\config.json\'' - : '__dirname + \'/../config/config.json\''; + const path = Support.isWindows() + ? '__dirname + \'/..\\config\\config.json\'' + : '__dirname + \'/../config/config.json\''; gulp .src(Support.resolveSupportPath('tmp')) @@ -104,9 +104,9 @@ const gulp = require('gulp'); }); it('correctly injects the reference to the custom config file', done => { - let path = Support.isWindows() - ? '__dirname + \'/..\\my\\configuration-file.json\'' - : '__dirname + \'/../my/configuration-file.json\''; + const path = Support.isWindows() + ? '__dirname + \'/..\\my\\configuration-file.json\'' + : '__dirname + \'/../my/configuration-file.json\''; gulp .src(Support.resolveSupportPath('tmp'))