Skip to content

Commit

Permalink
Migrates jasmine_node_test() to use @aspect_rules_js.
Browse files Browse the repository at this point in the history
Refs #48.

This commit includes a handful of changes which needed to be landed all at once to avoid an awkward migration period.

First we need to actually change the `jasmine_node_test()` macro to use `@aspect_rules_js`. There is no `@aspect_rules_jasmine`, so this needs to be done by manually invoking the `jasmine` binary via the rule generated by `npm_translate_lock()`. It generates a config file which explicitly lists its direct dependencies as test files. This means there is no convention to follow for test files (like `_test.js` or `.spec.js`), the only requirement is that it is a direct dependency of the `jasmine_node_test()` target.

The config file needs to be passed in `args`, however that only works for direct `bazel test` invocations. The `web_test_suite()` target wraps this binary and drops `args`, so they need to be repeated in that context. This breaks abstraction a little bit, but is small and simple enough to not be too big a deal.

Second we need to fix the errors this casues:

1. Adds `//:node_modules/*` dependencies where needed. `@npm//*` deps are still needed to type check things, but won't resolve at runtime. These dependencies are duplicated for now which doesn't seem to cause problems. Eventually the `@npm//*` dependencies will be dropped altogether.
2. Removes `@bazel/runfiles` from `jasmine_node_test()` targets because it fails (throws "`$BAZEL_WORKSPACE` is not set" error) and because it isn't needed. Since everything in `@aspect_rules_js` is in a single file tree, runfiles are just available at their root relative paths. This removes all but one usage of `@bazel/runfiles` which is still needed for a `nodejs_binary()` target.
3. Adds `debug` dependency to `//common/testing:webdriver`. This is necessary so `devtools` (a transitive dep of `webdriverio`) can import `debug` without an explicit dependency on it. This is a workaround for a pnpm-compatibility bug in WebDriverIO which should be removed once [the fix](webdriverio/webdriverio#8542) lands.
  • Loading branch information
dgp1130 committed Jul 20, 2022
1 parent 30efb5b commit c288f99
Show file tree
Hide file tree
Showing 52 changed files with 107 additions and 120 deletions.
1 change: 1 addition & 0 deletions common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ts_project(
"//common/models:prerender_annotation",
"@npm//@types/jasmine",
"@npm//node-html-parser",
"//:node_modules/node-html-parser",
],
)

Expand Down
7 changes: 5 additions & 2 deletions common/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ts_project(
":effects",
":test_server",
"//common:http",
"//:node_modules/http-status-codes",
"//:node_modules/tree-kill",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//http-status-codes",
Expand All @@ -51,10 +53,10 @@ ts_project(
":devserver",
":effect_tester",
"//common:http",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//http-status-codes",
"//:node_modules/http-status-codes",
],
)

Expand Down Expand Up @@ -229,6 +231,8 @@ ts_project(
":test_server",
"@npm//@types/node",
"@npm//webdriverio",
"//:node_modules/debug", # TODO(#48): Remove after WebDriver supports pnpm.
"//:node_modules/webdriverio",
],
)

Expand All @@ -240,7 +244,6 @@ ts_project(
":devserver",
":webdriver",
"effect_tester",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
"@npm//webdriverio",
],
Expand Down
3 changes: 1 addition & 2 deletions common/testing/devserver_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { URL } from 'url';
import { StatusCodes } from 'http-status-codes';
import { runfiles } from '@bazel/runfiles';
import * as http from '../http';
import { Server, useDevserver } from './devserver';
import { EffectTester } from './effect_tester';

const devserver = runfiles.resolvePackageRelative('devserver_test_server');
const devserver = 'common/testing/devserver_test_server';

describe('devserver', () => {
describe('Server', () => {
Expand Down
6 changes: 1 addition & 5 deletions common/testing/webdriver_test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { runfiles } from '@bazel/runfiles';
import * as webdriverio from 'webdriverio';
import { useDevserver } from './devserver';
import { EffectTester } from './effect_tester';
import { useWebDriver, webDriverTestTimeout } from './webdriver';

const devserverBinary =
runfiles.resolvePackageRelative('webdriver_test_server');

describe('webdriver', () => {
describe('useWebDriver()', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('common/testing/webdriver_test_server');

it('manages a WebDriver session without a server under test', async () => {
const remoteSpy = spyOn(webdriverio, 'remote').and.callThrough();
Expand Down
1 change: 0 additions & 1 deletion examples/components/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/components/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('components', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/components/devserver');
const wd = useWebDriver(devserver);

it('renders', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/custom_bundling/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/custom_bundling/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('custom bundling', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/custom_bundling/devserver');
const wd = useWebDriver(devserver);

it('renders a custom bundled page', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/data/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('data', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/data/devserver');
const wd = useWebDriver(devserver);

describe('index page', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/declarative_shadow_dom/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/declarative_shadow_dom/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { getColor, useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('Declarative Shadow DOM', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/declarative_shadow_dom/devserver');
const wd = useWebDriver(devserver);

it('attaches the declarative shadow root to its host', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/javascript/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/javascript/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('JavaScript', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/javascript/devserver');
const wd = useWebDriver(devserver);

it('renders component', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/minimal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ts_project(
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@types/jasmine",
"@npm//@bazel/runfiles",
],
)

Expand Down
5 changes: 1 addition & 4 deletions examples/minimal/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('minimal', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/minimal/devserver');
const wd = useWebDriver(devserver);

it('renders', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/multi_page/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/multi_page/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { getColor, useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('multi_page', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/multi_page/devserver');
const wd = useWebDriver(devserver);

describe('index page', () => {
Expand Down
1 change: 0 additions & 1 deletion examples/prerender_resources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ts_project(
testonly = True,
data = [":prerender"],
deps = [
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
"@npm//@types/node",
],
Expand Down
3 changes: 1 addition & 2 deletions examples/prerender_resources/generator_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { promises as fs } from 'fs';
import { runfiles } from '@bazel/runfiles';

const prerenderedDir = runfiles.resolvePackageRelative('prerender');
const prerenderedDir = 'examples/prerender_resources/prerender';

describe('Prerender Resources', () => {
it('prerenders `hello.txt`', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/resources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/resources/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('resources', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/resources/devserver');
const wd = useWebDriver(devserver);

it('renders with resources', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
5 changes: 1 addition & 4 deletions examples/scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../common/testing/webdriver';

const devserverBinary = runfiles.resolvePackageRelative('devserver');

describe('Scripts', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver('examples/scripts/devserver');
const wd = useWebDriver(devserver);

it('renders with scripts', async () => {
Expand Down
4 changes: 4 additions & 0 deletions examples/site/blog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ prerender_pages(
lib_deps = [
"//packages/rules_prerender",
"//examples/site/common:links",
"//:node_modules/markdown-it",
"@npm//markdown-it",
"@npm//@types/markdown-it",
"@npm//@types/node",
Expand All @@ -30,10 +31,13 @@ ts_project(
":blog_prerender_for_test",
"@npm//@types/jasmine",
"@npm//node-html-parser",
"//:node_modules/node-html-parser",
],
)

jasmine_node_test(
name = "blog_test",
# TODO(#48): Turn on after declarative shadow DOM can be used in `@aspect_rules_js`.
tags = ["manual"],
deps = [":blog_test_lib"],
)
6 changes: 5 additions & 1 deletion examples/site/components/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ prerender_component(
srcs = ["base.ts"],
tsconfig = "//:tsconfig.json",
source_map = True,
lib_deps = ["//packages/rules_prerender"],
lib_deps = [
"//packages/rules_prerender",
"//:node_modules/rules_prerender",
],
styles = [":styles"],
visibility = ["//examples/site:__subpackages__"],
deps = [
Expand All @@ -30,6 +33,7 @@ ts_project(
":base_prerender_for_test",
"@npm//@types/jasmine",
"@npm//node-html-parser",
"//:node_modules/node-html-parser",
],
)

Expand Down
7 changes: 5 additions & 2 deletions examples/site/components/counter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ prerender_component(
srcs = ["counter_prerender.ts"],
tsconfig = "//:tsconfig.json",
source_map = True,
lib_deps = ["//packages/rules_prerender"],
lib_deps = [
"//packages/rules_prerender",
"//:node_modules/rules_prerender",
],
scripts = [":scripts"],
visibility = ["//examples/site:__subpackages__"],
)
Expand All @@ -31,6 +34,7 @@ ts_project(
":counter_prerender_for_test",
"@npm//@types/jasmine",
"@npm//node-html-parser",
"//:node_modules/node-html-parser",
],
)

Expand Down Expand Up @@ -62,7 +66,6 @@ ts_project(
deps = [
"//common/testing:devserver",
"//common/testing:webdriver",
"@npm//@bazel/runfiles",
"@npm//@types/jasmine",
],
)
Expand Down
7 changes: 2 additions & 5 deletions examples/site/components/counter/counter_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { runfiles } from '@bazel/runfiles';
import { useDevserver } from '../../../../common/testing/devserver';
import { useWebDriver, webDriverTestTimeout } from '../../../../common/testing/webdriver';

const devserverBinary =
runfiles.resolvePackageRelative('counter_test_cases_devserver');

describe('Counter', () => {
const devserver = useDevserver(devserverBinary);
const devserver = useDevserver(
'examples/site/components/counter/counter_test_cases_devserver');
const wd = useWebDriver(devserver);

it('increments when the increment button is clicked', async () => {
Expand Down
2 changes: 2 additions & 0 deletions examples/site/components/footer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ prerender_component(
lib_deps = [
"//examples/site/common:links",
"//packages/rules_prerender",
"//:node_modules/rules_prerender",
],
styles = [":styles"],
visibility = ["//examples/site:__subpackages__"],
Expand All @@ -29,6 +30,7 @@ ts_project(
":footer_prerender_for_test",
"@npm//@types/jasmine",
"@npm//node-html-parser",
"//:node_modules/node-html-parser",
],
)

Expand Down
Loading

0 comments on commit c288f99

Please sign in to comment.