Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const {
combineSchemasInFileList,
} = require('../combine-js-to-schema');
const fs = require('fs');
const os = require('os');
const path = require('path');

describe('combine-js-to-schema', () => {
let tmpdir;

beforeEach(() => {
tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegen-combine-'));
});

afterEach(() => {
fs.rmSync(tmpdir, {recursive: true, force: true});
});

it('expands symlinked directories into source files', () => {
const sourceDir = path.join(tmpdir, 'source');
const symlinkDir = path.join(tmpdir, 'symlink');
fs.mkdirSync(sourceDir);
fs.symlinkSync(
sourceDir,
symlinkDir,
process.platform === 'win32' ? 'junction' : 'dir',
);

fs.writeFileSync(
path.join(sourceDir, 'NativeSample.ts'),
`
import type {TurboModule} from 'react-native';
import * as TurboModuleRegistry from 'TurboModuleRegistry';

export interface Spec extends TurboModule {
sampleMethod: () => void;
}

export default TurboModuleRegistry.get<Spec>('Sample');
`,
);

const schema = combineSchemasInFileList(
[symlinkDir],
null,
null,
'SampleSpec',
);

expect(Object.keys(schema.modules)).toEqual(['NativeSample']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function expandDirectoriesIntoFiles(
): Array<string> {
return fileList
.flatMap(file => {
if (!fs.lstatSync(file).isDirectory()) {
if (!fs.statSync(file).isDirectory()) {
return [file];
}
return globSync('**/*{,.fb}.{js,ts,tsx}', {
Expand Down