diff --git a/beforeTest.js b/beforeTest.js new file mode 100644 index 0000000..fcfb0b6 --- /dev/null +++ b/beforeTest.js @@ -0,0 +1,2 @@ +const generateConfig = require('./generateConfig') +generateConfig() diff --git a/package.json b/package.json index 41747a5..1f9beee 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "网易云音乐 NodeJS 版 API", "scripts": { "start": "node app.js", - "test": "mocha -r intelli-espower-loader -t 20000 server.test.js main.test.js --exit", + "test": "node beforeTest.js && mocha -r intelli-espower-loader -t 30000 server.test.js main.test.js --exit", "lint": "eslint \"**/*.{js,ts}\"", "lint-fix": "eslint --fix \"**/*.{js,ts}\"", "prepare": "husky install", diff --git a/test/album.test.js b/test/album.test.js index 2a6a1b9..e633ec4 100644 --- a/test/album.test.js +++ b/test/album.test.js @@ -1,11 +1,12 @@ const assert = require('assert') const axios = require('axios') const host = global.host || 'http://localhost:3000' - +const config = require('../util/config.json') describe('测试获取歌手专辑列表是否正常', () => { it('数据的 code 应该为200', (done) => { const qs = { id: 32311, + cookie: config.anonymous_token, } axios diff --git a/test/comment.test.js b/test/comment.test.js index 612f670..f198151 100644 --- a/test/comment.test.js +++ b/test/comment.test.js @@ -1,11 +1,12 @@ const assert = require('assert') const axios = require('axios') const host = global.host || 'http://localhost:3000' - +const config = require('../util/config.json') describe('测试获取评论是否正常', () => { it('数据的 code 应该为200', (done) => { const qs = { id: 32311, + cookie: config.anonymous_token, } axios diff --git a/test/lyric.test.js b/test/lyric.test.js index 41886e4..5f6bb2a 100644 --- a/test/lyric.test.js +++ b/test/lyric.test.js @@ -1,11 +1,12 @@ const assert = require('assert') const axios = require('axios') const host = global.host || 'http://localhost:3000' - +const config = require('../util/config.json') describe('测试获取歌词是否正常', () => { it('数据应该有 lrc 字段', (done) => { const qs = { id: 347230, + cookie: config.anonymous_token, } axios diff --git a/test/music_url.test.js b/test/music_url.test.js index 58eedf3..8c02f68 100644 --- a/test/music_url.test.js +++ b/test/music_url.test.js @@ -1,13 +1,14 @@ const assert = require('assert') const axios = require('axios') const host = global.host || 'http://localhost:3000' - +const config = require('../util/config.json') describe('测试获取歌曲是否正常', () => { it('歌曲的 url 不应该为空', (done) => { const qs = { id: 462791935, br: 999000, realIP: '116.25.146.177', + cookie: config.anonymous_token, } axios diff --git a/test/search.test.js b/test/search.test.js index e80dea5..6f67368 100644 --- a/test/search.test.js +++ b/test/search.test.js @@ -1,12 +1,13 @@ const assert = require('assert') const axios = require('axios') const host = global.host || 'http://localhost:3000' - +const config = require('../util/config.json') describe('测试搜索是否正常', () => { it('获取到的数据的 name 应该和搜索关键词一致', (done) => { const qs = { keywords: '海阔天空', type: 1, + cookie: config.anonymous_token, } axios .get(`${host}/search`, { diff --git a/util/config.json b/util/config.json index ed6e50b..40f0f6a 100644 --- a/util/config.json +++ b/util/config.json @@ -1,4 +1,5 @@ -{ "anonymous_token": "登录网易云音乐网页版,此字段值替换为cookie中MUSIC_U对应的值", +{ + "anonymous_token": "bf8bfeabb1aa84f9c8c3906c04a04fb864322804c83f5d607e91a04eae463c9436bd1a17ec353cf742a0e13bf4a3d0575ac3ffbf24b9c165993166e004087dd3a20e6c18bed612c072ea5b4f70e962ab276621b2ff13050f1471df55ea867f53807e650dd04abd3fb8130b7ae43fcc5b", "resourceTypeMap": { "0": "R_SO_4_", "1": "R_MV_5_", @@ -8,4 +9,4 @@ "5": "R_VI_62_", "6": "A_EV_2_" } -} +} \ No newline at end of file