How to use resolvePath method in Testcafe

Best JavaScript code snippet using testcafe

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

api.js

Source: api.js Github

copy
1/**
2 * NOTE HOST、HOST_M 是在 config 中通过 defineConstants 配置的
3 * 只所以不在代码中直接引用,是因为 eslint 会报 no-undef 的错误,因此用如下方式处理
4 */
5/* eslint-disable */
6export const host = HOST
7export const wss_host = WSS_HOST
8
9/* eslint-enable */
10
11export const pathname = '/api/wx'
12
13const resolvePath = api => `${host + pathname}/${api}`
14
15// common
16export const API_PRELOAD = resolvePath('preload')
17export const API_QRCODE = resolvePath('qrcode')
18export const API_BANNER_LIST = resolvePath('extendContent')
19export const API_QUERY_CODE_SCENE = resolvePath('qrcode/scene')
20
21// user
22export const API_USER_LOGIN = resolvePath('login')
23export const API_USER_INFO = resolvePath('signup')
24export const API_USER_SIGNIN = resolvePath('user/signin')
25export const API_USER_PHONE = resolvePath('userPhone')
26export const API_QUERY_USER_INFO = resolvePath('user/info')
27export const API_QUERY_USERINFO_BYID = resolvePath('onePerson')
28export const API_QUERY_CUSTOMER_INFO = resolvePath('customer/myCustomer')
29export const API_QUERY_MYREPORT = resolvePath('customer/myReport')
30export const API_QUERY_DOCUMENTVERIFY = resolvePath('documentVerify')
31
32export const API_QUERY_DOCUMENTVERIFY_list = resolvePath('documentVerify/list')
33export const API_QUERY_TADRAINGE = resolvePath('taDrainage')
34
35
36// chat
37export const API_CHAT_HISTORY = resolvePath('chat/history')
38export const API_CHAT_SEND = wss_host + '/wx/chat'
39export const API_CHAT_FRIENDS = resolvePath('chat/with')
40export const API_UPLOAD_IMAGE = resolvePath('image')
41export const API_CHAT_READED = resolvePath('chat/message')
42
43// card
44export const API_CARDS_LIST = resolvePath('cards')
45export const API_CARDS_APPLY = resolvePath('cards/apply')
46export const API_FORM_ID = resolvePath('formid')
47export const API_UPDATE_PHOTO = resolvePath('userInfo/updatePhoto')
48
49// project
50export const API_INDEX_CUSTOMER = resolvePath('indexCustomer')
51export const API_ITEMS_LIST = resolvePath('building/list')
52export const API_ITEMS_DETAIL = resolvePath('buildingSelectId')
53export const API_ITEMS_TYPE = resolvePath('tdBuildingType')
54export const API_ACTIVITY_GROUP = resolvePath('helpActivityAndGroup')
55export const API_LOCATION_CITYP = resolvePath('location/city')
56export const API_TACUSTOMIMG = resolvePath('taCustomImg')
57export const API_INDEX_PROJECTS = resolvePath('building/main')
58export const API_INDEX_ICONS = resolvePath('taMiniappOrgIcon')
59
60
61
62export const API_HOUSE_LIST = resolvePath('listHousingResources')
63export const API_PRESELECTION_RECORD = resolvePath('listPreselectionRecord')
64export const API_RAISE_CHECK = resolvePath('check/raise')
65export const API_RAISE_PROFILE = resolvePath('taRaise')
66export const API_SAVE_RAISE_RECORD = resolvePath('taRaiseRecord')
67export const API_RATSE_RECORD = resolvePath('taRaiseRecord/list')
68export const API_RATSE_DETAIL = resolvePath('taRaiseRecord')
69export const API_RATSE_ORDER = resolvePath('unifiedOrder')
70export const API_CANCEL_ORDER = resolvePath('cancel')
71export const API_HOUSE_DETAIL = resolvePath('getHousingDetailById')
72export const API_ADD_PRESELECTION = resolvePath('taPreselectionRecord')
73export const API_CANCEL_PRESELECTION = resolvePath('taPreselectionRecordCancel')
74export const API_APARTMENT_TYPE = resolvePath('listBuildApartmentBySalesBatchId')
75export const API_SALESBATCH_LIST = resolvePath('taSalesBatch/choice')
76export const API_NOTICE_INFO = resolvePath('getNoticeInfo')
77export const API_SALES_BATCH = resolvePath('taSalesBatch')
78export const API_ADDLIVE_NUM = resolvePath('addVisitNum')
79export const API_LIVE_DEATIL = resolvePath('taLiveActivity')
80// /wx/location/city?location=lon,lat
81
82//sign
83export const API_CONTRACT_USER = resolvePath('contract/user/add')
84export const API_CONTRACT_GET = resolvePath('contract/user/get')
85export const API_CONTRACT_AUTO = resolvePath('contract/auto')
86export const API_CONTRACT_MANUAL = resolvePath('contract/manual')
87export const API_CONTRACT_CHECK = resolvePath('contract/check')
88
89// shop
90export const API_GOODS_LIST = resolvePath('goods')
91export const API_GOODS_BUILDING = resolvePath('goodsToBuilding')
92export const API_GOODS_EXCHANGE = resolvePath('goods/exchange')
93export const API_GOODS_EXCHANGE_RECORDS = resolvePath('taPointsExchange')
94export const API_POINTS_RECORDS = resolvePath('taPointsRecords')
95export const API_POINTS_RULE = resolvePath('tdPointsRules')
96export const API_POINTS_ADRESS = resolvePath('person/city')
97export const API_GOODS_BELONGS = resolvePath('goodsToBuilding')
98
99// client
100export const API_CLIENT_LIST = resolvePath('customer/recommend/mine')
101export const API_RECOMENT_CLIENT = resolvePath('customer/new')
102export const API_CLIENT_PROGRESS = resolvePath('customer')
103export const API_TYPE_DATA = resolvePath('awesome/dict/recommendcustomer')
104
105// report
106export const API_REPORT_LIST = resolvePath('myReport')
107export const API_REPORT_CLIENT = resolvePath('customer/report')
108export const API_RECOMMEND_GET = resolvePath('customer/recommend/get')
109export const API_RECOMMEND_EDIT = resolvePath('customer/recommend/edit')
110
111// common
112export const API_ITEMS_UV = resolvePath('project/hot')
113export const API_CARDS_UV = resolvePath('consultant/hot')
114export const API_ACTIVITY_UV = resolvePath('activity/pvNum')
115export const API_NEWS_UV = resolvePath('taNews/pvNum')
116
117export const API_CARDS_LIKE = resolvePath('consultant/like')
118export const API_ITEMS_LIKE = resolvePath('project/like')
119export const API_ACTIVITY_LIKE = resolvePath('activity/like')
120export const API_NEWS_LIKE = resolvePath('news/like')
121
122export const API_CARDS_SHARE = resolvePath('consultant/share')
123export const API_ITEMS_SHARE = resolvePath('project/share')
124export const API_ACTIVITY_SHARE = resolvePath('activity/share')
125export const API_HELP_SHARE = resolvePath('help/share')
126export const API_GROUP_SHARE = resolvePath('group/share')
127export const API_HFIVE_SHARE = resolvePath('h5/share')
128export const API_NEWS_SHARE = resolvePath('news/share')
129export const API_HOUSE_SHARE = resolvePath('houseApp/share')
130export const API_HOUSE_POSTER = resolvePath('housePost/share')
131export const API_LIVE_SHARE = resolvePath('liveApp/share')
132export const API_LIVE_POSTER = resolvePath('livePost/share')
133
134export const API_INDEX_SHARE = resolvePath('main/share')
135
136export const API_ACTIVITY_FAVOR = resolvePath('activity/save')
137export const API_NEWS_FAVOR = resolvePath('news/save')
138export const API_CARD_FAVOR = resolvePath('card/save')
139export const API_PROJECT_FAVOR = resolvePath('project/save')
140
141// 埋点接口
142export const API_BURIED_POINT = resolvePath('taPersonVisitRecord')
143
144
145// activity
146export const API_ACTIVITY_LIST = resolvePath('buildingDynamiceList')
147//拼团
148export const API_GROUP_LIST = resolvePath('taShareRecord')
149//助力
150export const API_HELP_LIST = resolvePath('helpInitiateRecord')
151
152// save activity
153export const API_ACTIVITY_SAVE = resolvePath('save/buildingDynamiceList')
154
155export const API_ACTIVITY_DETAIL = resolvePath('buildingDynamiceInfo')
156// signup
157export const API_ACTIVITY_SIGNUP = resolvePath('activityDynamicEnlistAdd')
158// signin
159export const API_ACTIVITY_SIGNIN = resolvePath('taCheckin/activity')
160
161// news
162export const API_NEWS_LIST = resolvePath('taNews')
163
164
165// feedback
166export const API_FEEDBACK_SUBMIT = resolvePath('taCustomerMessage')
167
168
169// getCode
170export const API_GET_CODE = resolvePath('captcha')
171
172// checkCode
173export const API_CHECK_CODE = resolvePath('check/captcha')
174
175
176// /wx/registerConsultantOneClick
177// registerConsultant
178export const API_PUT_REGISTER = resolvePath('registerConsultant')
179
180// registerConsultantOneClick
181export const API_PUT_REGISTERCONSULTANT = resolvePath('registerConsultantOneClick')
182
183// city
184export const API_CITY_LIST = resolvePath('tdCity')
185
186
187// policy
188export const API_POLICY_LIST = resolvePath('taPolicy')
189
190//agent
191
192export const API_AGENT_LIST = resolvePath('agent/recommend/mine')
193
194export const API_REGISTER_AGENT = resolvePath('registerAgent')
195
196// agent change
197export const API_AGENT_CHANNEL = resolvePath('customer/recommend/becomeChannel')
198
199export const API_AGENT_CURRENT = resolvePath('user/current')
200
201export const API_EDIT_AGENT = resolvePath('editPerson')
202
203// 活动列表-新
204export const API_ACTNEW_LIST = resolvePath('activity/list')
205
206// 助力
207export const API_HELP_DETAIL = resolvePath('helpActivity')
208export const API_HELP_CREATE = resolvePath('helpInitiateRecord')
209export const API_HELP_FRIEND = resolvePath('helpRecord')
210
211//签到
212export const API_CHECKIN_DETAILS = resolvePath('buildingDynamiceEnlistInfo')
213export const API_CHECKIN_ACTIVE = resolvePath('buildingDynamicCheckin')
214
215// 拼团
216export const API_GROUP_DETAIL = resolvePath('taShareActivity')
217export const API_GROUP_CREATE = resolvePath('taShareRecord')
218export const API_GROUP_JOIN = resolvePath('taShareChildRecord')
219
220//person
221export const API_MY_CUSTOMER = resolvePath('inventory/customer/statistics')
222export const API_CUSTOMER_LIST = resolvePath('inventory/customer/statistics')
223export const API_CUSTOMER_DETAIL = resolvePath('inventory/customer')
224export const API_VISIT_RECORD = resolvePath('taPersonVisitRecord')
225export const API_ACTIVITY_LIST_CUSTOMER = resolvePath('customer/activity/list')
226export const API_FOLLOW_LIST = resolvePath('taCustomerFollowUpRecord')
227export const API_SEX_INFO = resolvePath('genderStatistic')
228export const API_ECHERTS_DAILY = resolvePath('customerStatisticDaily')
229export const API_ECHERTS_MONTH = resolvePath('customerStatisticMonthly')
230export const API_BUILDING_TYPE = resolvePath('getByBuildingIdSelectBuildingProjectType')
231export const API_CONSULTANT_VISIT_RECORD = resolvePath('activityVisitRecord')
232export const API_MORE_ACTIVITY = resolvePath('visitRecord/activity')
233export const API_SHARE_LIST = resolvePath('shareRecords')
234export const API_SHARE_INFOLIST = resolvePath('sharePersonInfoList')
235export const API_BIND_CUSTOMER = resolvePath('judgeBindCustomer')
236// 消息模板
237export const API_TEMPLATE_TYPE = resolvePath('template/of/')
238
Full Screen

util.js

Source: util.js Github

copy
1/**
2 * Tencent is pleased to support the open source community by making WePY available.
3 * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4 * 
5 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6 * http://opensource.org/licenses/MIT
7 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8 */
9
10
11var assert = require('assert');
12var util = require('../lib/util.js').default;
13
14
15describe('util.js', () => {
16
17    it('$resolvePath', () => {
18
19        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', 'page2'), '/page/abc/efg/hij/page2', `resolvePath('/page/abc/efg/hij/klm', 'page2')`);
20
21        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '.'), '/page/abc/efg/hij/klm', `resolvePath('/page/abc/efg/hij/klm', '.')`);
22        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '..'), '/page/abc/efg/hij/klm', `resolvePath('/page/abc/efg/hij/klm', '..')`);
23
24        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', 'a'), '/page/abc/efg/hij/a', `resolvePath('/page/abc/efg/hij/klm', 'a')`);
25
26        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '.page2'), '/page/abc/efg/hij/page2', `resolvePath('/page/abc/efg/hij/klm', '.page2')`);
27
28        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '.a'), '/page/abc/efg/hij/a', `resolvePath('/page/abc/efg/hij/klm', '.a')`);
29
30        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '..page2'), '/page/abc/efg/hij/page2', `resolvePath('/page/abc/efg/hij/klm', '..page2')`);
31
32        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '..aa'), '/page/abc/efg/hij/aa', `resolvePath('/page/abc/efg/hij/klm', '..aa')`);
33
34        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './page2'), '/page/abc/efg/hij/page2', `resolvePath('/page/abc/efg/hij/klm', './page2')`);
35
36        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '../page2'), '/page/abc/efg/page2', `resolvePath('/page/abc/efg/hij/klm', '../page2')`);
37
38        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '.../page2'), '/page/abc/efg/page2', `resolvePath('/page/abc/efg/hij/klm', '.../page2')`);
39
40        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '..../page2'), '/page/abc/efg/page2', `resolvePath('/page/abc/efg/hij/klm', '..../page2')`);
41
42        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../page2'), '/page/abc/efg/page2', `resolvePath('/page/abc/efg/hij/klm', './../page2')`);
43
44        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../../page2'), '/page/abc/page2', `resolvePath('/page/abc/efg/hij/klm', './../../page2')`);
45
46        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../.../page2'), '/page/abc/page2', `resolvePath('/page/abc/efg/hij/klm', './../.../page2')`);
47
48        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../../../page2'), '/page/page2', `resolvePath('/page/abc/efg/hij/klm', './../../../page2')`);
49
50        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../../../../page2'), '/page2', `resolvePath('/page/abc/efg/hij/klm', './../../../../page2')`);
51
52        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', './../../../../../page2'), '/page2', `resolvePath('/page/abc/efg/hij/klm', './../../../../page2')`);
53
54        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '/page2'), '/page2', `resolvePath('/page/abc/efg/hij/klm', '/page2')`);
55
56        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '//page2'), '/page2', `resolvePath('/page/abc/efg/hij/klm', '//page2')`);
57        assert.strictEqual(util.$resolvePath('/page/abc/efg/hij/klm', '/./page2'), '/page2', `resolvePath('/page/abc/efg/hij/klm', '/./page2')`);
58
59    });
60
61
62
63
64    it('$getParams', () => {
65
66        let p;
67
68        p = util.$getParams('index?a=1&b=2');
69
70        assert.strictEqual(Object.keys(p).length, 2, `$getParams('index?a=1&b=2')`);
71        assert.strictEqual(p.a, '1');
72        assert.strictEqual(p.b, '2');
73
74        p = util.$getParams('index?a=1&b=2&c=' + encodeURIComponent('中国'));
75
76        assert.strictEqual(Object.keys(p).length, 3, `$getParams('index?a=1&b=2')`);
77        assert.strictEqual(p.a, '1');
78        assert.strictEqual(p.b, '2');
79        assert.strictEqual(p.c, '中国');
80
81    });
82
83});
Full Screen

webpack.config.base.js

Source: webpack.config.base.js Github

copy
1const HtmlWebpackPlugin = require('html-webpack-plugin');
2const CopyWebpackPlugin = require('copy-webpack-plugin');
3const { VueLoaderPlugin } = require('vue-loader');
4const path = require('path');
5const {resolvePath} = require('./utils');
6const webpack = require('webpack');
7const MiniCssExtractPlugin = require("mini-css-extract-plugin");
8let isDev = global._ENV == 'development';
9module.exports = {
10  entry: {
11    main: [ resolvePath('src/main.ts')]
12  } ,
13  output: {
14    // 打包后的文件存放的路径
15    path:  isDev ? resolvePath('dist') : resolvePath('lib/dist'),
16    publicPath: isDev? './': '/devTools/',
17    // 打包后输出文件的文件名
18    filename:isDev ? 'js/bundle.js' :'js/[name].[contenthash].js',
19    chunkFilename: isDev ? 'js/[name].[hash].js' :'js/[name].[contenthash].js',
20  },
21  resolve: {
22    extensions: ['.ts', '.js', '.vue', '.d.ts', '.json'],
23    alias: {
24      '@': resolvePath('src'),
25      '@store$':resolvePath('src/store/index.js'),
26      '@components':resolvePath('src/components'),
27      '@pages':resolvePath('src/pages'),
28      '@assets':resolvePath('src/assets')
29    }
30  },
31
32  module: {
33    rules: [
34      {
35        test: /\.vue$/,
36        loader: 'vue-loader',
37        include:[resolvePath('src')],
38        exclude:/node_modules/,
39        options: {
40          presets: [['@babel/preset-env']], // https://www.babeljs.cn/docs/plugins/preset-env
41          plugins: ['@babel/plugin-syntax-dynamic-import'],
42          cacheDirectory: isDev ? resolvePath('cache/dev') : false
43        }
44      }, 
45      {
46        test: /\.js$/,
47        loader: 'babel-loader',
48        include:[
49          resolvePath('src'),
50          resolvePath('node_modules/element-plus')
51        ],
52        exclude:/node_modules\/(?!element\-plus)/,
53        options: {
54          cacheDirectory:  isDev ? resolvePath('cache/dev') : false
55        }
56      },
57      {
58        test: /\.ts$/,
59        loader: 'ts-loader',
60        include:[
61          resolvePath('src'),
62          resolvePath('node_modules/element-plus')
63        ],
64        exclude:/node_modules\/(?!element\-plus)/,
65      },
66      {
67        test: /\.(png|jpe?g|gif|svg|pdf)(\?.*)?$/,
68        use: {
69          loader: 'url-loader',
70          options: {
71            limit: 2000,
72            name: 'img/[name].[hash:7].[ext]'
73          }
74        }
75      }, {
76        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
77        use: {
78          loader: 'url-loader',
79          options: {
80            limit: 10000,
81            name: 'media/[name].[hash:7].[ext]'
82          }
83        }
84      }, {
85        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
86        include:[
87          resolvePath('src'),
88          resolvePath('node_modules/element-plus')
89        ],
90        use: {
91          loader: 'url-loader',
92          options: {
93            limit: 10000,
94            name: 'fonts/[name].[hash:7].[ext]'
95          }
96        }
97      },
98      {
99        test: /\.css$/,
100        include:[
101          resolvePath('src'),
102          resolvePath('node_modules/element-plus')
103        ],
104        use: (function(){
105          let loaders = ['css-loader'];
106          if (!isDev) {
107            loaders.unshift(MiniCssExtractPlugin.loader)
108          } else {
109            loaders.unshift('style-loader')
110          }
111          return loaders;
112        })()
113      },
114      {
115        test: /\.scss$/,
116        use: [
117          'style-loader',
118          'css-loader',
119          'sass-loader'
120        ]
121      }
122    ]
123  },
124
125  plugins: [
126    new HtmlWebpackPlugin({
127      filename: 'index.html',
128      template: resolvePath('src/index.html'),
129      inject: true,
130      title: 'super-mock',
131      favicon: false
132    }),
133    new VueLoaderPlugin(),
134    // new CopyWebpackPlugin({
135    //   patterns: [
136    //     {from: resolvePath('static'), to: 'dist/static'}
137    //   ]
138    // })
139  ]
140}
141
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Testcafe on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)