Skip to content

Commit

Permalink
chore: deno housekeeping (#31)
Browse files Browse the repository at this point in the history
* chore: add npm prefix to fs-extra types

* test: uncomment tests using objectContaining
  • Loading branch information
MaSch0212 authored Nov 1, 2024
1 parent 65adfeb commit b91a07d
Show file tree
Hide file tree
Showing 24 changed files with 107 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/expect": "jsr:@std/expect@^1.0.5",
"@std/testing": "jsr:@std/[email protected]",
"@std/testing": "jsr:@std/testing@^1.0.4",
"@std/text": "jsr:@std/text@^1.0.7",
"@types/fs-extra": "npm:@types/fs-extra@^11.0.4",
"@types/node": "npm:@types/node@^22.7.5",
Expand Down
6 changes: 4 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/src/codegen/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import { OpenApiParser } from '../parse/parser.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/parse/parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import { cwd } from 'node:process';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';
import * as YAML from 'yaml';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/asset-manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { basename, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

export class AssetManager {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/file-system.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import type { Nullable } from './type.utils.ts';
Expand Down
131 changes: 66 additions & 65 deletions packages/core/src/utils/schema.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { expect } from '@std/expect';
import { describe, it } from '@std/testing/bdd';

import { createCombinedSchema, createStringSchema } from '../../tests/schema-factory.ts';
import {
createCombinedSchema,
createObjectSchema,
createStringSchema,
createUnknownProperty,
} from '../../tests/schema-factory.ts';
import { resolveAnyOfAndAllOf } from './schema.utils.ts';

describe('resolveAnyOfAndAllOf', () => {
Expand All @@ -14,73 +19,69 @@ describe('resolveAnyOfAndAllOf', () => {
expect(result).toBeUndefined();
});

// TODO: Uncomment as soon as @std/expect has new version (https://github.com/denoland/std/pull/6065)
// it('should resolve schema from allOf and anyOf', () => {
// const schema = createObjectSchema({
// name: 'root',
// properties: [createUnknownProperty('prop0')],
// required: ['prop0'],
// allOf: [createObjectSchema({ properties: [createUnknownProperty('prop1')], required: ['prop1'] })],
// anyOf: [createObjectSchema({ properties: [createUnknownProperty('prop2')], required: ['prop2'] })],
// });
it('should resolve schema from allOf and anyOf', () => {
const prop0 = createUnknownProperty('prop0');
const prop1 = createUnknownProperty('prop1');
const prop2 = createUnknownProperty('prop2');
const schema = createObjectSchema({
name: 'root',
properties: [prop0],
required: ['prop0'],
allOf: [createObjectSchema({ properties: [prop1], required: ['prop1'] })],
anyOf: [createObjectSchema({ properties: [prop2], required: ['prop2'] })],
});

// const expectedResult = expect.objectContaining(
// createObjectSchema({
// name: 'root',
// properties: [
// expect.objectContaining(createUnknownProperty('prop0')),
// expect.objectContaining(createUnknownProperty('prop1')),
// expect.objectContaining(createUnknownProperty('prop2')),
// ],
// required: ['prop0', 'prop1', 'prop2'],
// }),
// );
const expectedResult = expect.objectContaining(
createObjectSchema({
name: 'root',
properties: [prop0, prop1, prop2],
required: ['prop0', 'prop1'],
}),
);

// const result = resolveAnyOfAndAllOf(schema, true);
// expect(result).toEqual(expectedResult);
// });
const result = resolveAnyOfAndAllOf(schema, true);
expect(result).toEqual(expectedResult);
});

// TODO: Uncomment as soon as @std/expect has new version (https://github.com/denoland/std/pull/6065)
// it('should merge properties from allOf and anyOf recursively', () => {
// const schema = createCombinedSchema({
// name: 'root',
// allOf: [
// createObjectSchema({
// properties: [createUnknownProperty('prop1')],
// required: ['prop1'],
// }),
// ],
// anyOf: [
// createCombinedSchema({
// allOf: [
// createObjectSchema({
// properties: [createUnknownProperty('prop2')],
// required: ['prop2'],
// }),
// ],
// anyOf: [
// createObjectSchema({
// properties: [createUnknownProperty('prop3')],
// required: ['prop3'],
// }),
// ],
// }),
// ],
// });
it('should merge properties from allOf and anyOf recursively', () => {
const prop1 = createUnknownProperty('prop1');
const prop2 = createUnknownProperty('prop2');
const prop3 = createUnknownProperty('prop3');
const schema = createCombinedSchema({
name: 'root',
allOf: [
createObjectSchema({
properties: [prop1],
required: ['prop1'],
}),
],
anyOf: [
createCombinedSchema({
allOf: [
createObjectSchema({
properties: [prop2],
required: ['prop2'],
}),
],
anyOf: [
createObjectSchema({
properties: [prop3],
required: ['prop3'],
}),
],
}),
],
});

// const expectedResult = expect.objectContaining(
// createObjectSchema({
// name: 'root',
// properties: [
// expect.objectContaining(createUnknownProperty('prop1')),
// expect.objectContaining(createUnknownProperty('prop2')),
// expect.objectContaining(createUnknownProperty('prop3')),
// ],
// required: ['prop1'],
// }),
// );
const expectedResult = expect.objectContaining(
createObjectSchema({
name: 'root',
properties: [prop1, prop2, prop3],
required: ['prop1'],
}),
);

// const result = resolveAnyOfAndAllOf(schema, true);
// expect(result).toEqual(expectedResult);
// });
const result = resolveAnyOfAndAllOf(schema, true);
expect(result).toEqual(expectedResult);
});
});
3 changes: 1 addition & 2 deletions packages/core/src/utils/source-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe('SourceBuilder', () => {
};
const sb = SourceBuilder.fromString(str, options);
expect(sb.toString()).toEqual(str);
// TODO: Uncomment as soon as @std/expect has new version (https://github.com/denoland/std/pull/6065)
// expect(sb.options).toEqual(expect.objectContaining(options));
expect(sb.options).toEqual(expect.objectContaining(options));
});
});

Expand Down
19 changes: 9 additions & 10 deletions packages/core/src/utils/string-builder/string-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ describe('fromString', () => {
expect(sb.toString()).toEqual(str);
});

// TODO: Uncomment as soon as @std/expect has new version (https://github.com/denoland/std/pull/6065)
// it('should create a StringBuilder instance with the given string and options', () => {
// const str = 'test string';
// const options: Partial<StringBuilderOptions> = {
// newLine: '\r\n',
// };
// const sb = StringBuilder.fromString(str, options);
// expect(sb.toString()).toEqual(str);
// expect(sb.options).toEqual(expect.objectContaining(options));
// });
it('should create a StringBuilder instance with the given string and options', () => {
const str = 'test string';
const options: Partial<StringBuilderOptions> = {
newLine: '\r\n',
};
const sb = StringBuilder.fromString(str, options);
expect(sb.toString()).toEqual(str);
expect(sb.options).toEqual(expect.objectContaining(options));
});
});

describe('build', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/kotlin/src/generators/models/model-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context,
[
kt.parameter('basePath', kt.refs.string(), { default: 'defaultBasePath' }),
kt.parameter('client', kt.refs.okhttp3.okHttpClient(), {
default: 'defaultClient'
default: 'defaultClient',
}),
],
null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/kotlin/tests/openapi-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from 'node:path';

import { afterEach, describe, test } from '@std/testing/bdd';
import { restore, stub } from '@std/testing/mock';
// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import { OpenApiGenerator, toCustomCase } from '@goast/core';
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/file-builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import { type AppendParam, type AppendValue, isAppendValue, type Nullable, SourceBuilder } from '@goast/core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/tests/openapi-models.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'node:path';

// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

import { OpenApiGenerator, toCustomCase } from '@goast/core';
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { build, type BuildOptions, emptyDir } from '@deno/dnt';
import { resolve } from 'node:path';
// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

type GoastNpmOptions = {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
// @deno-types="@types/fs-extra"
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';

declare const __dirname: string | undefined;
Expand Down
8 changes: 4 additions & 4 deletions test/utils/verify.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @deno-types="@types/fs-extra"
import { toKebabCase } from '@std/text';
// @deno-types="npm:@types/fs-extra"
import fs from 'fs-extra';
import { spawn } from 'node:child_process';
import { basename, dirname, join, relative, resolve } from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import * as util from 'node:util';
import { spawn } from 'node:child_process';
import { repoRootDir } from './paths.ts';
import process from 'node:process';
import { toKebabCase } from '@std/text';

type VerifyError = 'no-expect-file' | 'verify-failed';

Expand Down

0 comments on commit b91a07d

Please sign in to comment.