play-urls v0.0.8
Play-URLs
a simple and quick way to verify proper status/content of many urls
how to use
npm i -D play-urls/yarn -D play-urls- create a
.play-urls.config.ts(or.js) in your project root - define the config (see plain configuration)
note: if integrated into a pipeline it's recommended to use the playwright docker image and install this package with --ignore-scripts flag
plain configuration
import defineConfig from play-urls and configure everything required (it's typed, just check via intellisense ;), otherwise check the types).
also this library allows a file-based url configuration via defineUrl (recognized via urlGlob-option within the config)
// .play-urls.config.ts
import { defineConfig } from 'play-urls/define';
export default defineConfig({
browsers: ['chromium'],
browserConfig: {
headless: !!process.env.CI,
},
urlGlob: 'src/**/*.play-urls.spec.{js,ts}',
urls: [
{
url: 'https://example.com',
name: 'example-com',
},
],
});// some.play-urls.spec.ts
import { defineUrl } from 'play-urls/define';
export default defineUrl({
url: 'https://google.com',
name: 'example-com-from-file',
});note: it's highly recommended to use .(test|spec).{js,ts} or any other test-file naming convention to easily exclude these files from linters (such as ESLint) and show that they're testing files and no actual source files
run via JS/TS
you can run it also via js/ts, just import run from play-urls
import { run } from 'play-urls';
// somewhere
run();
// or with inline config
run({
browsers: ['chromium'],
// ...
});CLI args / envs
| arg | env | default | definition |
|---|---|---|---|
--config | CONFIG | .play-urls.config | overwrite the default filename/-path of the config |
--urlglob | URLGLOB | - (none) | overwrite the urlGlob (this one is preferred over the config one if both provided) |
--errorlog | ERRORLOG | play-urls-errors.json | overwrite the errorLog (this one is preferred over the config one if both provided) |
## examples ##
## config
# via env
CONFIG=my.config npx play-urls
# via arg
npx play-urls --config my.config
## urlglob
# via env
URLGLOB="src/**/*.my-url.spec.{ts,js}" npx play-urls
# via arg
npx play-urls --urlglob "src/**/*.my-url.spec.{ts,js}"
## errorLog
# via env
ERRORLOG="custom-errors.json" npx play-urls
# via arg
npx play-urls --errorlog "custom-errors.json"note: if env and arg are passed at once (let's say CONFIG=... and --config ...) env will be preferred!