Skip to content

Commit

Permalink
Typescript fixes in package.json (#887)
Browse files Browse the repository at this point in the history
* Add cypress types globally for tsc

* Bump @types/node

* Add globalThis shim for cypress package.

* Add es6 types and iterator option for more modern syntax in e2e tests

* Fixed types

* Real tests for TimeTag

* Add .nvmrc

* New package scripts.

Move checking client types to lint stage.
Add watch scripts for checking types in all sub-packages.

* Update package.json

Co-authored-by: Paweł Lesiecki <pawel.lesiecki@allegro.pl>

* Fix lint:types arguments

* Pin advised version of setup-gcloud action

* remove local .nvmrc

* Fix scripts in package.json

Co-authored-by: Paweł Lesiecki <pawel.lesiecki@allegro.pl>
  • Loading branch information
adrianmroz-allegro and plesiecki authored Mar 30, 2022
1 parent 2bed1e9 commit a3fb9e6
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v2

- name: Authenticate on GCP
uses: google-github-actions/setup-gcloud@master
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v2

- name: Authenticate on GCP
uses: google-github-actions/setup-gcloud@master
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
Expand Down
18 changes: 18 additions & 0 deletions cypress/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2017-2022 Allegro.pl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/

// Remove after updating to tsc 3.4
declare const globalThis: any;
10 changes: 4 additions & 6 deletions cypress/integration/split-tile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,10 @@ context("Split Tile", () => {

splitsContainer().trigger("dragenter");

// @ts-ignore Fix types!
splitTile("Channel").then(([channelSplit]) => {
const { x, width } = channelSplit.getBoundingClientRect();
const { left, width } = channelSplit.getBoundingClientRect();

dragMask().trigger("drop", { clientX: x + width / 2 });
dragMask().trigger("drop", { clientX: left + width / 2 });

shouldHaveSplits("Page");
});
Expand All @@ -252,11 +251,10 @@ context("Split Tile", () => {
splitsContainer().trigger("dragenter");

splitTile("Page")
// @ts-ignore Fix types!
.then(([timeSplit]) => {
const { x, width } = timeSplit.getBoundingClientRect();
const { left, width } = timeSplit.getBoundingClientRect();

dragMask().trigger("drop", { clientX: x + width });
dragMask().trigger("drop", { clientX: left + width });

shouldHaveSplits("Page", "Channel", "City Name");
});
Expand Down
15 changes: 12 additions & 3 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"compilerOptions": {
"downlevelIteration": true,
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"]
"lib": [
"es5",
"es6",
"dom"
],
"types": [
"cypress"
]
},
"include": ["**/*.ts"]
"include": [
"**/*.ts"
]
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,27 @@
"test:common": "mocha --exit --require ./test/setup/mocha.js 'src/common/**/*.mocha.{ts,tsx}'",
"test:client": "mocha --exit --require ./test/setup/mocha.js 'src/client/**/*.mocha.{ts,tsx}' --file 'src/client/utils/test-utils/jsdom-setup.ts'",
"test:server": "mocha --exit --require ./test/setup/mocha.js 'src/server/**/*.mocha.ts'",
"test:client-types": "npm run tsc -- --noEmit -p src/client/tsconfig.json",
"test:size": "size-limit",
"watch:test:common": "npm run test:common -- --watch --watch-files 'src/common/**/*.mocha.ts'",
"watch:test:client": "npm run test:client -- --watch --watch-files 'src/client/**/*.mocha.tsx' --watch-files 'src/client/**/*.mocha.ts'",
"watch:test:server": "npm run test:server -- --watch --watch-files 'src/server/**/*.mocha.ts'",
"test-watcher": "mocha --require ./test/setup/mocha.js --watch",
"start": "./bin/turnilo",
"start:dev": "NODE_ENV=dev-hmr ./bin/turnilo",
"start:examples": "npm run start -- --examples",
"start:dev": "NODE_ENV=dev-hmr ./bin/turnilo",
"start:dev:examples": "npm run start:dev -- --examples",
"build:client": "webpack --config config/webpack.prod.js",
"build:server": "npm run tsc -- -p src/server/tsconfig.json",
"build:server": "tsc -p src/server/tsconfig.json",
"build": "npm-run-all -s clean build:server build:client",
"clean": "rimraf build/*",
"tsc": "tsc",
"tsc:watch": "tsc -p tsconfig.json -w --pretty",
"watch:types:server": "tsc -p src/server/tsconfig.json -w --pretty --noEmit",
"watch:types:client": "tsc -p src/client/tsconfig.json -w --pretty --noEmit",
"watch:types:e2e": "tsc -p cypress/tsconfig.json -w --pretty --noEmit",
"watch:types:common": "tsc -p src/common/tsconfig.json -w --pretty --noEmit",
"lint": "npm-run-all -p lint:*",
"lint:types": "tsc --noEmit -p src/client/tsconfig.json",
"lint:ts": "tslint -p . --format verbose",
"lint:ts:fix": "tslint -p . --fix",
"lint:sass": "sass-lint -v",
"fix": "npm-run-all -s fix:*",
"fix:ts": "tslint -p . --fix",
"e2e": "start-server-and-test start:examples http://localhost:9090/health/ready 'cypress run'",
"e2e:dev": "cypress open",
"check": "npm-run-all -c -p lint test build e2e"
Expand Down Expand Up @@ -133,7 +134,7 @@
"@types/mocha": "2.2.46",
"@types/moment-timezone": "0.5.12",
"@types/nock": "9.1.3",
"@types/node": "8.5.2",
"@types/node": "14.0.4",
"@types/nopt": "3.0.29",
"@types/randomstring": "1.1.6",
"@types/react": "16.14.24",
Expand Down
35 changes: 19 additions & 16 deletions src/common/models/time-tag/time-tag.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@
* limitations under the License.
*/

import { testImmutableClass } from "immutable-class-tester";
import { TimeTag, TimeTagJS } from "./time-tag";
import { expect } from "chai";
import { TimeTag } from "./time-tag";

describe("TimeTag", () => {
// TODO: reimplement this test as simpler cases without immutable-class-tester - it checks too much
it.skip("is an immutable class", () => {
testImmutableClass<TimeTagJS>(TimeTag, [
{
name: "dodo",
time: new Date("2015-10-15T19:20:00Z"),
lastTimeChecked: new Date("2015-10-15T19:20:13Z")
},
{
name: "wikipedia",
time: new Date("2015-10-15T19:21:00Z"),
lastTimeChecked: new Date("2015-10-15T19:21:13Z")
}
]);
it("should read passed name values", () => {
const timeTag = TimeTag.fromJS({ name: "foobar" });
expect(timeTag.name).to.be.equal("foobar");
});

it("should parse passed time value", () => {
const timeTag = TimeTag.fromJS({ name: "foobar", time: "2020-01-01" });
expect(timeTag.time).to.be.deep.equal(new Date("2020-01-01"));
});

it("should parse passed lastTimeChecked value", () => {
const timeTag = TimeTag.fromJS({ name: "foobar", lastTimeChecked: "2020-01-01" });
expect(timeTag.lastTimeChecked).to.be.deep.equal(new Date("2020-01-01"));
});

it("should use time value if lastTimeChecked is missing", () => {
const timeTag = TimeTag.fromJS({ name: "foobar", time: "2020-01-01" });
expect(timeTag.lastTimeChecked).to.be.deep.equal(new Date("2020-01-01"));
});
});
10 changes: 1 addition & 9 deletions src/common/models/time-tag/time-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ const defaultTimeTag: TimeTagValue = {

export class TimeTag extends Record<TimeTagValue>(defaultTimeTag) {

static isTimeTag(candidate: any): candidate is TimeTag {
return candidate instanceof TimeTag;
}

static fromJS({ name, time: timeJS, lastTimeChecked: lastTimeCheckedJS }: TimeTagJS): TimeTag {
const time = timeJS ? new Date(timeJS) : undefined;
const lastTimeChecked = lastTimeCheckedJS ? new Date(lastTimeCheckedJS) : time;
Expand All @@ -56,10 +52,6 @@ export class TimeTag extends Record<TimeTagValue>(defaultTimeTag) {
}

public changeTime(time: Date, lastTimeChecked: Date): TimeTag {
return new TimeTag({
name: this.name,
time,
lastTimeChecked
});
return this.set("time", time).set("lastTimeChecked", lastTimeChecked);
}
}
3 changes: 2 additions & 1 deletion src/server/www.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import * as http from "http";

import { AddressInfo } from "net";
import app from "./app";
import { SERVER_SETTINGS, START_SERVER } from "./config";

Expand Down Expand Up @@ -46,7 +47,7 @@ if (START_SERVER) {
});

server.on("listening", () => {
var address = server.address();
const address = server.address() as AddressInfo;
console.log(`Turnilo is listening on address ${address.address} port ${address.port}`);
});

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"esModuleInterop": true,
"jsx": "react",
"lib": ["dom", "es6", "es5"],
"types": ["node", "express", "mocha", "webpack-env"]
"types": ["node", "express", "mocha", "cypress", "webpack-env"]
}
}

0 comments on commit a3fb9e6

Please sign in to comment.