Я пытаюсь использовать ALM-Rangers / Countdown-Widget-Extension в качестве примера, чтобы добавить модульное тестирование в мое собственное веб-расширение VSS SDK.
Мне удалось загрузить и запустить тесты, но когда я пытаюсь применить это к моему собственному проекту (форк Microsoft / vsts-team-calendar), я получаю сообщение об ошибке при запуске tsc ./tests/TestSpec.ts
:
src / Calendar / Utils / TestDate.ts (1,29): ошибка TS2307: не удается найти модуль 'VSS / Utils / Date'.
TestSpec.ts:
import jasmine = require("jasmine");
import * as DateUtils from "../src/Calendar/Utils/TestDate";
describe('JavaScript addition operator', function() {
it ('adds two numbers together', function(){
expect(1+2).toEqual(3);
});
});
describe('getDatesInRange', () => {
it('gets dates in range', () => {
expect(DateUtils.getDatesInRange(
new Date(2018, 4, 25),
new Date(2018,4,26)
))
.toEqual([
new Date(2018, 4, 25),
new Date(2018,4,26)
]);
});
});
TestDate.ts:
import Utils_Date = require("VSS/Utils/Date");
export function getDatesInRange(startDate:Date, endDate: Date): Date[] {
const dates = [];
let current: Date = startDate;
while (current.getTime() <= endDate.getTime()) {
dates.push(new Date(<any>current));
current = Utils_Date.addDays(current, 1);
}
return dates;
}
webpack module.rules:
module: {
rules: [{ test: /\.tsx?$/, loader: "ts-loader" }],
},
tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"module": "amd",
"moduleResolution": "node",
"target": "es5",
"outDir": "dist/",
"rootDir": "src/",
"lib": [
"es5",
"dom",
"es2015.promise"
],
"importHelpers": true,
"noEmitHelpers": true,
"skipLibCheck": true,
"types": [
"vss-web-extension-sdk",
"fullcalendar",
"jquery"
]
},
"include": [
"src/**/*.ts"
]
}
Структура файла:
root
|-- dist
|-- node_modules
|-- scripts
|-- tests
|-- TestSpec.js
|-- TestSpec.ts
|-- src
|-- Calendar
|-- Controls
|-- *Control.ts
|-- Dialogs
|-- EditEventDialog.ts
|-- Enhancers
|-- *Enhancer.ts
|-- EventSources
|-- *EventSource.ts
|-- Utils
|-- TestDate.ts
|-- Color.ts
|-- Date.ts
|-- Guid.ts
|-- Promise.ts
|-- Views
|-- CalendarView.ts
|-- CalendarView.ts
|-- Calendar.ts
|-- CalendarServices.ts
|-- Contracts.ts
|-- DateRelativeToValidator.ts
|-- EventSourceCollection.ts
|-- Extension.ts
|-- NamedListData.ts
|-- static
|-- css
|-- images
|-- *.html
package.json
tsconfig.json
vss-extension.json
webpack.config.js
Вот некоторые потенциально важные разделы vss-extension.json. Не могу сказать, что понимаю эту часть:
"files": [
{
"path": "static/images",
"addressable": true
},
{
"path": "static/css",
"addressable": true
},
{
"path": "dist",
"packagePath": "js",
"addressable": true
},
{
"path": "node_modules/vss-web-extension-sdk/lib",
"addressable": true,
"packagePath": "sdk"
},
{
"path": "node_modules/fullcalendar/dist",
"addressable": true,
"packagePath": "dist/fullcalendar"
},
{
"path": "node_modules/moment",
"addressable": true,
"packagePath": "dist/moment"
},
{
"path": "node_modules/moment-timezone",
"addressable": true,
"packagePath": "dist/moment-timezone"
},
{
"path": "node_modules/jquery/dist",
"addressable": true,
"packagePath": "dist/jquery"
},
{
"path": "node_modules/tablesorter/dist",
"addressable": true,
"packagePath": "dist/tablesorter"
},
{
"path": "static/calendar.html",
"addressable": true,
"contentType": "text/html"
},
{
"path": "static/calendarServices.html",
"addressable": true,
"contentType": "text/html"
},
{
"path": "static/daysOffControls.html",
"addressable": true,
"contentType": "text/html"
},
{
"path": "static/freeFormControls.html",
"addressable": true,
"contentType": "text/html"
},
{
"path": "LICENSE.txt",
"addressable": true,
"contentType": "text/html"
}
],
и более из конфигурации веб-пакета:
return {
entry: {
"main": "./" + path.relative(process.cwd(), path.join(__dirname, "src", "Calendar", "Extension.ts")),
"calendarServices": "./" + path.relative(process.cwd(), path.join(__dirname, "src", "Calendar", "CalendarServices.ts")),
"freeformEventControl": "./" + path.relative(process.cwd(), path.join(__dirname, "src", "Calendar", "Controls", "FreeFormEventControl.ts")),
"capacityEventControl": "./" + path.relative(process.cwd(), path.join(__dirname, "src", "Calendar", "Controls", "CapacityEventControl.ts"))
},
output: {
filename: path.relative(process.cwd(), path.join(__dirname, "dist", "[name].js")),
libraryTarget: "amd",
},