Skip to content

Commit

Permalink
Mega commit
Browse files Browse the repository at this point in the history
- add tests for invoking links, which required big refactor of test framework
- reworked webpack to fix ie issues with debug library
  • Loading branch information
tompahoward committed Nov 19, 2020
1 parent 471461f commit 87f7290
Show file tree
Hide file tree
Showing 26 changed files with 1,020 additions and 184 deletions.
20 changes: 0 additions & 20 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .nycrc-browser-api-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exclude:
- 'dist/**/*.js'
- 'scripts/**/*.js'
- 'coverage/**/*.js'
- 'src/test/clients/waychaser-direct.js'
- 'src/test/clients/waychaser-via-webdriver-remote.js'
check-coverage: false

Expand Down
2 changes: 1 addition & 1 deletion .nycrc-browser-api-remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude:
- 'dist/**/*.js'
- 'scripts/**/*.js'
- 'coverage/**/*.js'
- 'src/test/clients/waychaser-via-webdriver-local-*.js'
- 'src/test/clients/waychaser-direct.js'
- 'src/test/clients/waychaser-via-webdriver-local.js'
check-coverage: false

Expand Down
3 changes: 2 additions & 1 deletion .nycrc-node-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ exclude:
- 'dist/**/*.js'
- 'scripts/**/*.js'
- 'coverage/**/*.js'
- 'src/test/clients/*.js'
- 'src/test/clients/waychaser-via-webdriver-remote.js'
- 'src/test/clients/waychaser-via-webdriver-local.js'
check-coverage: false
reporter:
- text-summary
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"eslint.alwaysShowStatus": true,
"editor.formatOnSave": true,
"cucumberautocomplete.onTypeFormat": true,
"cucumberautocomplete.steps": ["src/test/**/*.js"],
"cucumberautocomplete.steps": ["src/test/*.steps.js"],
"cucumberautocomplete.skipDocStringsFormat": true,
"cucumberautocomplete.syncfeatures": "src/test/**/*.feature",
"editor.codeActionsOnSave": {
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,47 @@ returns an API Resource Object (ARO)
## Get list of operations

- `ARO.operations`
- `ARO.op` ✅ (shorthand)
- `ARO.ops` ✅ (shorthand)
- `ARO.operations()`
- `ARO.getOperations()`

returns a map of API operation objects (AOO)

so the plan was to return a map of API operation objects (AOO), with the key being the rel. However it's perfectly fine to have
multiple operations with the same rel. So, we either need to:
- return a map of arrays,
- return a map with each value either being a AOO or an Array of AOO.

The former sucks from a refencing point of view. e.g., `ARO.ops[rel][0]()`
The later sucks because we need to test if AOO or array. e.g. `Array.isArray(ARO.ops[rel]) ? ARO.ops[rel][0]() : ARO.ops[rel]()`
The later sucks even more because most of the time, users would just do `ARO.ops[rel]()`, which will be fine until the day that
resource returns multiple links with the same rel.

For instance if you have a ARO that is a list, you can have multiple links with `rel=item` with different `anchor`s, which tells
you where to get each item in the data.

You could also have and ARO that has links with the same rel, that take a different number of parameters.

It's worth noting that the `http-link-header` library's `link.get(attr, value)` method returns an array.

Maybe if the ARO is a list, we can treat each item as a ARO. e.g. `ARO.data[9].operations` will return the operations just for that item. For more complexe structures `ARO.data.foo.bar.operations` will do the same. Doesn't feel ideal, because the data structre is not just a JSON. Also, things got to crap if the JSON has a field called `operations`

Instead, mayb we can use the anchor structure for the operations. e.g. for a list, `ARO.operations[9][rel]` would get the link with the rel for the 9th item in the list. Whereas `ARO.operations.foo.bar[rel]` would get the link with the rel for the item at `foo.bar`. Again this will fail if the data has a field with the same name as a rel. 😭

We probably need to be explicit about the anchor. Something like `ARO.operations[anchor][rel]`.e.g., For root links it might look like `ARO.operations['#'][rel]`.

What of `operations` returns a function? Then we could go `ARO.operations(rel)` for root and `ARO.operations(rel, {anchor="foo.bar})` or whatever other attribute we want to get it by.

If we do that, what should happen if `ARO.operations(rel, {anchor="foo.bar})` still finds multiple links? We'd still have the same problem that we started with, so we're going to have to always return an array, in order to not break clients when the server adds an extra link with the same rel.

So let's go with `ARO.operations(rel)` and `ARO.operations(rel, {anchor="foo.bar})` and `ARO.operations({anchor="foo.bar})` as all valid options. And they all return a set of operations, so `ARO.operations(rel, {anchor="foo.bar})[0]` is the same as `ARO.operations(rel)({anchor="foo.bar})[0]`

## Get specific operation

- `ARO.getOperation(rel)`
- `ARO[rel]`
- `ARO.operation(rel)`
- `ARO.operations[rel]`
- `ARO.op[rel]`
- `ARO.ops[rel]`

returns an API operation or an array of API operations

Expand Down
48 changes: 48 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
corejs: {
version: "3",
proposals: true,
},
useBuiltIns: "entry",
targets: {
ie: "11",
browsers: [
"ie >= 11",
"last 2 versions",
"> 0.2%",
"maintained node versions",
],
},
},
],
],
plugins: [
"add-module-exports",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-proposal-class-properties",
[
"@babel/transform-runtime",
{
regenerator: true,
},
],
"dynamic-import-webpack",
[
"@babel/plugin-transform-modules-commonjs",
{
allowTopLevelThis: true,
},
],
],
env: {
test: {
plugins: ["istanbul"],
sourceMaps: "inline",
retainLines: true,
},
},
};
3 changes: 2 additions & 1 deletion cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const FAIL_FAST = process.env.FAIL_FAST || "--fail-fast";
const NO_STRICT = process.env.NO_STRICT || "";

const outputDirectory = "test-results";
fs.mkdirSync(outputDirectory, { recursive: true });

function getFeatureGlob(RERUN, profile) {
/* istanbul ignore next: RERUN is not set for full test runs */
Expand All @@ -22,7 +23,7 @@ function generateConfig() {
const resultsDirectory = `${outputDirectory}/${profile}`;
fs.mkdirSync(resultsDirectory, { recursive: true });

const RERUN = `@cucumber-${profile}.rerun`;
const RERUN = `${outputDirectory}/@cucumber-${profile}.rerun`;
const FEATURE_GLOB = getFeatureGlob(RERUN, profile);
const FORMAT_OPTIONS = {
snippetInterface: "async-await",
Expand Down
Loading

0 comments on commit 87f7290

Please sign in to comment.