Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: documentationjs/documentation
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4ec2e867d5726cbe822979e32115a691f8c5b73c
Choose a base ref
..
head repository: documentationjs/documentation
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0113e5695f75ed42123baf03f85b5583bb9c7e3c
Choose a head ref
Showing with 219 additions and 129 deletions.
  1. +1 −1 __tests__/fixture/sort-order-alpha.input.js
  2. +58 −0 __tests__/lib/__snapshots__/sort.js.snap
  3. +15 −28 __tests__/lib/sort.js
  4. +4 −2 docs/USAGE.md
  5. +120 −87 package-lock.json
  6. +1 −1 package.json
  7. +3 −2 src/commands/shared_options.js
  8. +17 −8 src/sort.js
2 changes: 1 addition & 1 deletion __tests__/fixture/sort-order-alpha.input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Options: {"sortOrder": "alpha"}
// Options: {"sortOrder": ["alpha"]}

/** */
function b() {}
58 changes: 58 additions & 0 deletions __tests__/lib/__snapshots__/sort.js.snap
Original file line number Diff line number Diff line change
@@ -38,12 +38,26 @@ Array [
"sortKey": "b",
},
"name": "carrot",
"path": Array [
Object {
"name": "carrot",
"scope": "static",
"toc": true,
},
],
},
Object {
"context": Object {
"sortKey": "c",
},
"name": "bananas",
"path": Array [
Object {
"name": "bananas",
"scope": "static",
"toc": true,
},
],
},
]
`;
@@ -86,12 +100,26 @@ Array [
"sortKey": "b",
},
"name": "carrot",
"path": Array [
Object {
"name": "carrot",
"scope": "static",
"toc": true,
},
],
},
Object {
"context": Object {
"sortKey": "c",
},
"name": "bananas",
"path": Array [
Object {
"name": "bananas",
"scope": "static",
"toc": true,
},
],
},
]
`;
@@ -102,13 +130,43 @@ Array [
"context": Object {
"sortKey": "a",
},
"kind": "function",
"memberof": "classB",
"name": "apples",
},
Object {
"context": Object {
"sortKey": "c",
},
"kind": "function",
"memberof": "classB",
"name": "bananas",
},
Object {
"context": Object {
"sortKey": "b",
},
"memberof": "classB",
"name": "carrot",
},
]
`;

exports[`sort toc with files absolute path 3`] = `
Array [
Object {
"context": Object {
"sortKey": "a",
},
"kind": "function",
"memberof": "classB",
"name": "apples",
},
Object {
"context": Object {
"sortKey": "c",
},
"kind": "function",
"memberof": "classB",
"name": "bananas",
},
43 changes: 15 additions & 28 deletions __tests__/lib/sort.js
Original file line number Diff line number Diff line change
@@ -5,21 +5,16 @@ import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

test('sort stream alphanumeric', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const banana = { context: { sortKey: 'c' }, name: 'bananas' };

expect(sort([apples, carrot, banana])).toEqual([apples, carrot, banana]);
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

expect(sort([carrot, apples, banana])).toEqual([apples, carrot, banana]);
test('sort stream alphanumeric', function () {
expect(sort([apples, carrot, bananas])).toEqual([apples, carrot, bananas]);
expect(sort([carrot, apples, bananas])).toEqual([apples, carrot, bananas]);
});

test('sort stream with configuration', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

expect(
sort([apples, carrot, bananas], {
toc: ['carrot', 'bananas']
@@ -28,10 +23,6 @@ test('sort stream with configuration', function () {
});

test('sort stream with configuration and a section', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

const section = {
name: 'This is the banana type',
description: 'here lies bananas'
@@ -71,10 +62,6 @@ test('sort stream with configuration and a section', function () {

test('sort an already-sorted stream containing a section/description', function () {
// this happens in the 'serve' task
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

const section = {
name: 'This is the banana type',
description: 'here lies bananas'
@@ -114,10 +101,6 @@ test('sort an already-sorted stream containing a section/description', function
});

test('sort toc with files', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

const snowflake = {
name: 'snowflake',
file: path.join(__dirname, '../fixture/snowflake.md')
@@ -131,10 +114,6 @@ test('sort toc with files', function () {
});

test('sort toc with files absolute path', function () {
const apples = { context: { sortKey: 'a' }, name: 'apples' };
const carrot = { context: { sortKey: 'b' }, name: 'carrot' };
const bananas = { context: { sortKey: 'c' }, name: 'bananas' };

const snowflake = {
name: 'snowflake',
file: path.join(__dirname, '../fixture/snowflake.md')
@@ -150,6 +129,7 @@ test('sort toc with files absolute path', function () {
const apples = {
context: { sortKey: 'a' },
name: 'apples',
kind: 'function',
memberof: 'classB'
};
const carrot = {
@@ -160,6 +140,7 @@ test('sort toc with files absolute path', function () {
const bananas = {
context: { sortKey: 'c' },
name: 'bananas',
kind: 'function',
memberof: 'classB'
};

@@ -169,7 +150,13 @@ test('sort toc with files absolute path', function () {
};
expect(
sort([carrot, apples, bananas], {
sortOrder: 'alpha'
sortOrder: ['alpha']
})
).toMatchSnapshot();

expect(
sort([carrot, apples, bananas], {
sortOrder: ['kind', 'alpha']
})
).toMatchSnapshot();
});
6 changes: 4 additions & 2 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
@@ -56,8 +56,10 @@ Options:
--document-exported Generate documentation for all exported bindings
and members even if there is no JSDoc for them
[boolean] [default: false]
--sort-order The order to sort the documentation
[choices: "source", "alpha"] [default: "source"]
--sort-order The order to sort the documentation, may be
specified multiple times
[choices: "source", "alpha", "kind"]
[default: "source"]
--output, -o output location. omit for stdout, otherwise is a
filename for single-file outputs and a directory
name for multi-file outputs like html
Loading