mongoose при изменении версии nodejs получить ошибку Невозможно прочитать свойство 'replace' из неопределенного
Попытка проверить мангуст: https://github.com/Automattic/mongoose
Когда я изменил версию узла, npm.cmd "run-script" "test" не работает и выдает мне сообщение:
C:\2016\IT\nb\M11\22\mongoose\test\connection.test.js:145
var repl2 = repl1.replace('mongodb://', '').split(',');
^
Вот что я получаю:
"C:\Program Files\nodejs\npm.cmd" "run-script" "test"
> mongoose@4.6.9-pre test C:\2016\IT\nb\M11\21\mongoose
> mocha test/*.test.js test/**/*.test.js
C:\2016\IT\nb\M11\21\mongoose\test\connection.test.js:145
var repl2 = repl1.replace('mongodb://', '').split(',');
^
TypeError: Cannot read property 'replace' of undefined
at Suite.<anonymous> (C:\2016\IT\nb\M11\21\mongoose \test\connection.test.js:145:22)
at Object.create (C:\2016\IT\nb\M11\21\mongoose\node_modules\mocha\lib\interfaces\common.js:114:19)
at context.describe.context.context (C:\2016\IT\nb\M11\21\mongoose\node_modules\mocha\lib\interfaces\bdd.js:44:27)
at Suite.<anonymous> (C:\2016\IT\nb\M11\21\mongoose\test\connection.test.js:136:3)
at Object.create (C:\2016\IT\nb\M11\21\mongoose\node_modules\mocha\lib\interfaces\common.js:114:19)
at context.describe.context.context (C:\2016\IT\nb\M11\21\mongoose\node_modules\mocha\lib\interfaces\bdd.js:44:27)
at Object.<anonymous> (C:\2016\IT\nb\M11\21\mongoose\test\connection.test.js:16:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:\2016\IT\nb\M11\21\mongoose\node_modules\mocha\lib\mocha.js:222:27
at Array.forEach (native)
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Mircea\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "test"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! mongoose@4.6.9-pre test: `mocha test/*.test.js test/**/*.test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mongoose@4.6.9-pre test script 'mocha test/*.test.js test/**/*.test.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mongoose package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha test/*.test.js test/**/*.test.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mongoose
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mongoose
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\2016\IT\nb\M11\21\mongoose\npm-debug.log
Done.
TypeError: Cannot read property 'replace' of undefined
Перед установкой node-v6.9.1
"C:\Program Files\nodejs\npm.cmd" "run-script" "test"
> mongoose@4.6.9-pre test C:\2016\IT\nb\M11\21\mongoose
> mocha test/*.test.js test/**/*.test.js
Not testing multi-mongos support
You're not testing shards!
Please set the MONGOOSE_SHARD_TEST_URI env variable.
e.g: `mongodb://localhost:27017/database
Sharding must already be enabled on your database
(node:11752) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
.....
You're not testing replica sets!
Please set the MONGOOSE_SET_TEST_URI env variable.
e.g: `mongodb://localhost:27017/db,localhost…`
.................................!.................
(node:11752) DeprecationWarning: Mongoose: Query.prototype.stream() is deprecated in mongoose >= 4.5.0, use Query.prototype.cursor() instead
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
!.......................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
........................................................
.............................
1651 passing (2m)
2 failing
1) model create() creates in parallel:
Error: timeout of 1000ms exceeded. Ensure the done() callback is being called in this test.
2) query stream: pipe:
Uncaught Error: ENOENT: no such file or directory, open 'C:\tmp\_mongoose_stream_out.txt'
Done.
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Mircea\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run-script" "test"
npm ERR! node v7.1.0
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! mongoose@4.6.9-pre test: `mocha test/*.test.js test/**/*.test.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the mongoose@4.6.9-pre test script 'mocha test/*.test.js test/**/*.test.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the mongoose package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha test/*.test.js test/**/*.test.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs mongoose
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls mongoose
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\2016\IT\nb\M11\21\mongoose\npm-debug.log
Я смог запустить тест после того, как я сбросил базу данных с помощью Robomongo.
Я получаю: 1652 прохождения (3м) 3 провала
1 ответ
Строка 144 кода соединения определяет repl1 как process.env.MONGOOSE_SHARD_TEST_URI, что означает, что переменная окружения не установлена. Он должен быть установлен в uri для осколка монго, который тестируется.
Похоже, что вы в Windows, и вы можете сделать это, установив переменные среды, чтобы предоставить Node информацию, необходимую для запуска выбранной среды. MONGOOSE_SHARD_TEST_URI= узел вашего URI connection.test.js - подробнее здесь