-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(apidom-parser-adapter-api-design-systems-json): run tests in ESM
- Loading branch information
Showing
13 changed files
with
121 additions
and
40 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
packages/apidom-parser-adapter-api-design-systems-json/.eslintignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/**/*.js | ||
/**/*.mjs | ||
/**/*.cjs | ||
/dist | ||
/es | ||
/cjs | ||
/types | ||
/config | ||
/.nyc_output | ||
/node_modules | ||
/**/*.js |
5 changes: 3 additions & 2 deletions
5
packages/apidom-parser-adapter-api-design-systems-json/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/src/**/*.mjs | ||
/src/**/*.cjs | ||
/test/**/*.mjs | ||
/dist | ||
/es | ||
/cjs | ||
/types | ||
/NOTICE | ||
/swagger-api-apidom-parser-adapter-api-design-systems-json-*.tgz |
4 changes: 2 additions & 2 deletions
4
packages/apidom-parser-adapter-api-design-systems-json/.mocharc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"recursive": true, | ||
"spec": "test/**/*.ts", | ||
"file": ["test/mocha-bootstrap.cjs"] | ||
"spec": "test/**/*.mjs", | ||
"file": ["test/mocha-bootstrap.mjs"] | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/apidom-parser-adapter-api-design-systems-json/cjs/adapter.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default; | ||
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default; | ||
exports.__esModule = true; | ||
exports.parse = exports.namespace = exports.mediaTypes = exports.detectionRegExp = exports.detect = void 0; | ||
var _ramda = require("ramda"); | ||
var _ramdaAdjunct = require("ramda-adjunct"); | ||
var _apidomCore = require("@swagger-api/apidom-core"); | ||
var _apidomParserAdapterJson = require("@swagger-api/apidom-parser-adapter-json"); | ||
var _apidomNsApiDesignSystems = _interopRequireWildcard(require("@swagger-api/apidom-ns-api-design-systems")); | ||
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs")); | ||
exports.mediaTypes = _mediaTypes.default; | ||
const detectionRegExp = exports.detectionRegExp = /"version"\s*:\s*"(?<version_json>2021-05-07)"/; | ||
const detect = async source => detectionRegExp.test(source) && (await (0, _apidomParserAdapterJson.detect)(source)); | ||
exports.detect = detect; | ||
const parse = async (source, options = {}) => { | ||
const refractorOpts = (0, _ramda.propOr)({}, 'refractorOpts', options); | ||
const parserOpts = (0, _ramda.omit)(['refractorOpts'], options); | ||
const parseResultElement = await (0, _apidomParserAdapterJson.parse)(source, parserOpts); | ||
const { | ||
result | ||
} = parseResultElement; | ||
if ((0, _ramdaAdjunct.isNotUndefined)(result)) { | ||
const mainElement = _apidomNsApiDesignSystems.MainElement.refract(result, refractorOpts); | ||
mainElement.classes.push('result'); | ||
parseResultElement.replaceResult(mainElement); | ||
} | ||
return parseResultElement; | ||
}; | ||
exports.parse = parse; | ||
const namespace = exports.namespace = (0, _apidomCore.createNamespace)(_apidomNsApiDesignSystems.default); |
7 changes: 7 additions & 0 deletions
7
packages/apidom-parser-adapter-api-design-systems-json/cjs/media-types.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
exports.__esModule = true; | ||
exports.default = void 0; | ||
var _apidomNsApiDesignSystems = require("@swagger-api/apidom-ns-api-design-systems"); | ||
const jsonMediaTypes = new _apidomNsApiDesignSystems.ApiDesignSystemsMediaTypes(..._apidomNsApiDesignSystems.mediaTypes.filterByFormat('generic'), ..._apidomNsApiDesignSystems.mediaTypes.filterByFormat('json')); | ||
var _default = exports.default = jsonMediaTypes; |
23 changes: 23 additions & 0 deletions
23
packages/apidom-parser-adapter-api-design-systems-json/es/adapter.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { propOr, omit } from 'ramda'; | ||
import { isNotUndefined } from 'ramda-adjunct'; | ||
import { createNamespace } from '@swagger-api/apidom-core'; | ||
import { parse as parseJSON, detect as detectJSON } from '@swagger-api/apidom-parser-adapter-json'; | ||
import apiDesignSystemsNamespace, { MainElement } from '@swagger-api/apidom-ns-api-design-systems'; | ||
export { default as mediaTypes } from "./media-types.mjs"; | ||
export const detectionRegExp = /"version"\s*:\s*"(?<version_json>2021-05-07)"/; | ||
export const detect = async source => detectionRegExp.test(source) && (await detectJSON(source)); | ||
export const parse = async (source, options = {}) => { | ||
const refractorOpts = propOr({}, 'refractorOpts', options); | ||
const parserOpts = omit(['refractorOpts'], options); | ||
const parseResultElement = await parseJSON(source, parserOpts); | ||
const { | ||
result | ||
} = parseResultElement; | ||
if (isNotUndefined(result)) { | ||
const mainElement = MainElement.refract(result, refractorOpts); | ||
mainElement.classes.push('result'); | ||
parseResultElement.replaceResult(mainElement); | ||
} | ||
return parseResultElement; | ||
}; | ||
export const namespace = createNamespace(apiDesignSystemsNamespace); |
3 changes: 3 additions & 0 deletions
3
packages/apidom-parser-adapter-api-design-systems-json/es/media-types.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { mediaTypes, ApiDesignSystemsMediaTypes } from '@swagger-api/apidom-ns-api-design-systems'; | ||
const jsonMediaTypes = new ApiDesignSystemsMediaTypes(...mediaTypes.filterByFormat('generic'), ...mediaTypes.filterByFormat('json')); | ||
export default jsonMediaTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
packages/apidom-parser-adapter-api-design-systems-json/test/adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
packages/apidom-parser-adapter-api-design-systems-json/test/mocha-bootstrap.cjs
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
packages/apidom-parser-adapter-api-design-systems-json/test/mocha-bootstrap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as chai from 'chai'; | ||
import { jestSnapshotPlugin, addSerializer } from 'mocha-chai-jest-snapshot'; | ||
|
||
// @ts-ignore | ||
import * as jestApiDOMSerializer from '../../../scripts/jest-serializer-apidom'; | ||
// @ts-ignore | ||
import * as jestStringSerializer from '../../../scripts/jest-serializer-string'; | ||
|
||
chai.use(jestSnapshotPlugin()); | ||
addSerializer(jestApiDOMSerializer); | ||
addSerializer(jestStringSerializer); |