Skip to content

Commit

Permalink
Attempt to update test code and build rule.
Browse files Browse the repository at this point in the history
Unfortunately, the test fails because of
bazelbuild/rules_nodejs#2093
  • Loading branch information
gonzojive committed Jul 31, 2020
1 parent 927a655 commit 01370f6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 46 deletions.
18 changes: 12 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
#load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm//@bazel/karma:index.bzl", "karma_web_test", "karma_web_test_suite")
load(":execute.bzl", "concat")

package(default_visibility = ["//:__subpackages__"])
Expand Down Expand Up @@ -98,15 +99,20 @@ ts_library(
deps = [
":resize_lib",
":tilespec_lib",
"@npm//@types/chai",
"@npm//@types/mocha",
"@npm//@types/jasmine",
"@npm//chai",
"@npm//jasmine",
],
)

# ts_web_test(
# name = "testing",
# deps = [
# ":tests",
# ],
# )
karma_web_test(
name = "testing",
deps = [
":tests",
],
)

rollup_bundle(
name = "bundle",
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ You can alternatively manually install the latest version from GitHub:
1. Clone the repository to the *Gnome* extensions folder.

```shell
git clone https://github.com/gTile/gTile.git ~/.local/share/gnome-shell/extensions/gTile@vibou
git clone https://github.com/gTile/gTile.git
git checkout bazelify
```

2. Set up workspace dependencies. If you forget to run this command, bazel will
give errors.
2. (May not be necessary) Set up workspace dependencies. If you forget to run
this command, bazel will give errors.

```shell
bazel run @yarn//:yarn
bazel run @nodejs//:yarn
```

3. Build and install
Expand Down Expand Up @@ -150,8 +151,10 @@ you do need to install bazel.

### One-time setup

This may no longer be necessary as of 2020, but it doesn't hurt:

```shell
bazel run @yarn//:yarn
bazel run @nodejs//:yarn
```

### Build/Test
Expand All @@ -166,3 +169,12 @@ bazel test ...
```shell
bazel run :install-extension
```


### Add a new dependency

"dev" dependency:

```shell
bazel run @nodejs//:yarn -- add --dev "@bazel/karma"
```
20 changes: 20 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,23 @@ yarn_install(
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

# For testing, use Karma per
# Per https://bazelbuild.github.io/rules_nodejs/Karma.html

# Fetch transitive Bazel dependencies of @bazel/karma
load("@npm//@bazel/karma:package.bzl", "npm_bazel_karma_dependencies")
npm_bazel_karma_dependencies()

# Set up web testing, choose browsers we can test on
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()

load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")

browser_repositories(
# There is no GJS option. GJS is based on Mozilla's SpiderMonkey, though.
chromium = True,
firefox = True,
)
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@
"@bazel/bazelisk": "latest",
"@bazel/buildifier": "latest",
"@bazel/ibazel": "latest",
"@bazel/jasmine": "^2.0.1",
"@bazel/karma": "^2.0.1",
"@bazel/protractor": "^2.0.1",
"@bazel/rollup": "^2.0.1",
"@bazel/typescript": "^2.0.1",
"@types/chai": "^4.2.12",
"@types/jasmine": "^3.5.11",
"@types/mocha": "^8.0.0",
"chai": "^4.2.0",
"jasmine": "^3.6.1",
"jasmine-core": "^3.6.0",
"karma": "^5.0.2",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-jasmine": "^3.1.0",
"karma-requirejs": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"mocha": "^8.1.0",
"requirejs": "^2.3.6",
"rollup": "^2.23.0",
"typescript": "^3.9.7"
},
Expand Down
17 changes: 10 additions & 7 deletions resize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { expect } from 'chai';
import {describe, it} from 'mocha';

import {LineSegment, XY, parsePreset, Edges, Side, Rect, Size} from './tilespec';
import {coincidentEdgeMoves, MoveSpec, CoincidentMoveOptions} from './resize';

Expand All @@ -17,7 +20,7 @@ describe("coincidentEdgeMoves", function() {
const other = new Rect(new XY(100, 10), new Size(200, 190));

expect(coincidentEdgeMoves(move, [other], workArea, opts))
.toEqual({
.equal({
0: new MoveSpec(
other,
new Rect(new XY(95, 10), new Size(205, 190)))
Expand All @@ -38,7 +41,7 @@ describe("coincidentEdgeMoves", function() {
new Rect(new XY(1180, 1365), new Size(1380, 786))];
const workArea = new Rect(new XY(0, 579), new Size(2560, 1573));
expect(coincidentEdgeMoves(move, otherWindows, workArea, opts))
.toEqual({
.equal({
0: new MoveSpec(otherWindows[0], shifted[0]),
1: new MoveSpec(otherWindows[1], shifted[1]),
2: new MoveSpec(otherWindows[2], shifted[2]),
Expand All @@ -57,7 +60,7 @@ describe("coincidentEdgeMoves - tolerance handling", function() {
it("move rect shares right edge with left edge of other window - within tolerance", function() {
const opts = new CoincidentMoveOptions(new Size(.1, .1), 20.01);
expect(coincidentEdgeMoves(move, [other], workArea, opts))
.toEqual({
.equal({
0: new MoveSpec(
other,
new Rect(new XY(95, 10), new Size(220, 190)))
Expand All @@ -67,7 +70,7 @@ describe("coincidentEdgeMoves - tolerance handling", function() {
it("move rect shares right edge with left edge of other window - out of tolerance", function() {
const opts = new CoincidentMoveOptions(new Size(.1, .1), 10);
expect(coincidentEdgeMoves(move, [other], workArea, opts))
.toEqual({});
.equal({});
});
});

Expand All @@ -82,7 +85,7 @@ describe("coincidentEdgeMoves - tolerance 2", function() {
it("move rect shares right edge with left edge of other window - within tolerance", function() {
const opts = new CoincidentMoveOptions(new Size(.1, .1), 3.01);
expect(coincidentEdgeMoves(move, [other], workArea, opts))
.toEqual({
.equal({
0: new MoveSpec(
other,
new Rect(new XY(110, 10), new Size(188, 190)))
Expand All @@ -101,12 +104,12 @@ describe("Movespec.edgeTranslationDistance - simple translation", function() {
const move = new MoveSpec(
new Rect(new XY(10, 10), new Size(90, 190)),
new Rect(new XY(5, 3), new Size(90, 190)));
expect(translations(move)).toEqual([-7, -5, -7, -5])
expect(translations(move)).equal([-7, -5, -7, -5])
});
it("edge translations non-uniform", function() {
const move = new MoveSpec(
new Rect(new XY(10, 10), new Size(90, 190)),
new Rect(new XY(5, 3), new Size(80, 170)));
expect(translations(move)).toEqual([-7, -15, -27, -5])
expect(translations(move)).equal([-7, -15, -27, -5])
});
});
59 changes: 31 additions & 28 deletions tilespec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { expect } from 'chai';
import {describe, it} from 'mocha';

import {LineSegment, XY, parsePreset, adjoiningSides, Edges, Side, Rect, Size} from './tilespec';

describe('1 = 1', () => {
it('should do that', () => {
expect(1).toBe(1);
expect(1).eq(1);
});
});

describe("TileSpec.parsePreset", function() {
it("parsePreset should work", function () {
const roundtrip = function(s) {
const roundtrip = function(s: string) {
return parsePreset(s)
.map(x => x.toString())
.join(', ');
};
expect(roundtrip('3x3 0:0 1:1, 2x2 0:0 0:0'))
.toBe('3x3 0:0 1:1, 2x2 0:0 0:0');
.equal('3x3 0:0 1:1, 2x2 0:0 0:0');
});
});

describe("TileSpec.XY.dot", function() {
it("[1, 2].[3, 4]", function () {
expect(new XY(1, 2).dot(new XY(3, 4))).toBe(1*3 + 2*4);
expect(new XY(1, 2).dot(new XY(3, 4))).equal(1*3 + 2*4);
});
});

describe("XY", function() {
const [xUnit, yUnit] = [new XY(1, 0), new XY(0, 1)];
it("units are equal to selves", () => {
expect(xUnit).toEqual(xUnit.unit());
expect(yUnit).toEqual(yUnit.unit());
expect(xUnit).eql(xUnit.unit());
expect(yUnit).eql(yUnit.unit());
});

it("project", () => {
expect(new XY(40, .00124).project(xUnit.scale(1000)))
.toEqual(new XY(40, 0));
.eql(new XY(40, 0));
});
});

Expand All @@ -42,28 +45,28 @@ describe("TileSpec.LineSegment", function() {
const b = LineSegment.fromTwoPoints(new XY(4, 0), new XY(4, 10));

it("unit is 1", function() {
expect(a.direction()).toEqual(new XY(0, 1));
expect(b.direction()).toEqual(new XY(0, 1));
expect(a.direction()).eql(new XY(0, 1));
expect(b.direction()).eql(new XY(0, 1));
});

it("scaled direction is 3", function() {
expect(a.direction().scale(3)).toEqual(new XY(0, 3));
expect(a.direction().scale(3)).eql(new XY(0, 3));
});

it("[0, 5]->[0, 10] is 4 away from [4, 0]->[4, 10]", function () {
expect(a.perpVectorBetweenLines(b)).toEqual(new XY(4, 0));
expect(b.perpVectorBetweenLines(a)).toEqual(new XY(-4, 0));
expect(a.lineDistance(b)).toEqual(4);
expect(a.perpVectorBetweenLines(b)).eql(new XY(4, 0));
expect(b.perpVectorBetweenLines(a)).eql(new XY(-4, 0));
expect(a.lineDistance(b)).eql(4);
});

it("[0, 5]->[0, 10] is 4 away from [4, 0]->[4, 10]", function () {
const x = LineSegment.fromTwoPoints(new XY(4, 0), new XY(4, 10));
expect(a.perpVectorBetweenLines(b)).toEqual(new XY(4, 0));
expect(a.lineDistance(b)).toEqual(4);
expect(a.perpVectorBetweenLines(b)).eql(new XY(4, 0));
expect(a.lineDistance(b)).eql(4);
});

it("[0, 5]->[0, 10] unit dot is 1", function () {
expect(a.direction().dot(b.direction())).toEqual(1);
expect(a.direction().dot(b.direction())).eql(1);
});
});

Expand All @@ -74,13 +77,13 @@ describe("adjoiningSides", function() {
it("inset rect does not have adjoining edges", function() {
const aInsert = a.inset(new Size(5, 5));
expect(asArray(adjoiningSides(a.edges(), aInsert.edges(), tol)))
.toEqual([]);
.eql([]);
});

it("rect adjoins with its own edges", function() {
const aInsert = a.inset(new Size(0, 0));
expect(asArray(adjoiningSides(a.edges(), aInsert.edges(), tol)))
.toEqual([
.eql([
[Side.Top, Side.Top],
[Side.Bottom, Side.Bottom],
[Side.Left, Side.Left],
Expand All @@ -91,28 +94,28 @@ describe("adjoiningSides", function() {
it("rect adjoins with a shifted copy (shift right)", function() {
const b = a.translate(new XY(a.size.width, 20));
expect(asArray(adjoiningSides(a.edges(), b.edges(), tol)))
.toEqual([
.eql([
[Side.Right, Side.Left],
]);
});
it("rect adjoins with a shifted copy (shift down)", function() {
const b = a.translate(new XY(20, a.size.height));
expect(asArray(adjoiningSides(a.edges(), b.edges(), tol)))
.toEqual([
.eql([
[Side.Bottom, Side.Top],
]);
});
it("rect adjoins with a shifted copy (shift left)", function() {
const b = a.translate(new XY(-a.size.width,20));
expect(asArray(adjoiningSides(a.edges(), b.edges(), tol)))
.toEqual([
.eql([
[Side.Left, Side.Right],
]);
});
it("rect adjoins with a shifted copy (shift up)", function() {
const b = a.translate(new XY(32, -a.size.height));
expect(asArray(adjoiningSides(a.edges(), b.edges(), tol)))
.toEqual([
.eql([
[Side.Top, Side.Bottom],
]);
});
Expand All @@ -123,19 +126,19 @@ describe("Rect.translateEdge", function() {

it("increase bottom", function() {
expect(a.translateEdge(Side.Bottom, 4))
.toEqual(new Rect(new XY(10, 10), new Size(42, 84)));
.eql(new Rect(new XY(10, 10), new Size(42, 84)));
});
it("increase top", function() {
expect(a.translateEdge(Side.Top, 4))
.toEqual(new Rect(new XY(10, 14), new Size(42, 76)));
.eql(new Rect(new XY(10, 14), new Size(42, 76)));
});
it("increase right", function() {
expect(a.translateEdge(Side.Right, 4))
.toEqual(new Rect(new XY(10, 10), new Size(46, 80)));
.eql(new Rect(new XY(10, 10), new Size(46, 80)));
});
it("increase left", function() {
expect(a.translateEdge(Side.Left, -3))
.toEqual(new Rect(new XY(7, 10), new Size(45, 80)));
.eql(new Rect(new XY(7, 10), new Size(45, 80)));
});
});

Expand All @@ -145,12 +148,12 @@ describe("Rect.intersection", function() {

it("area of intersection", function() {
expect(a.intersection(b).size.area())
.toEqual(79*12);
.eql(79*12);
});

it("intersection", function() {
expect(a.intersection(b))
.toEqual(new Rect(new XY(40, 100), new Size(12, 79)));
.eql(new Rect(new XY(40, 100), new Size(12, 79)));
});
});

Expand Down

0 comments on commit 01370f6

Please sign in to comment.