<commit_before>/**
 * this checks if typings work as expected
 */
import assert from 'assert';
import * as schemas from './../helper/schemas';

describe('typings.test.js', () => {
    const codeBase = `
        import {create, RxDatabase, RxCollection, SchemaJSON} from '../';
    `;
    const transpileCode = async(code) => {
        const spawn = require('child-process-promise').spawn;
        const stdout = [];
        const stderr = [];
        const promise = spawn('ts-node', [
            '--compilerOptions', '{"target":"es6"}',
            '-p', code
        ]);
        const childProcess = promise.childProcess;
        childProcess.stdout.on('data', data => stdout.push(data.toString()));
        childProcess.stderr.on('data', data => stderr.push(data.toString()));
        try {
            await promise;
        } catch (err) {
            throw new Error(`could not run
                # Error: ${err}
                # Output: ${stdout}
                # ErrOut: ${stderr}
                `);
        }
    };

    describe('basic', () => {
        it('should sucess on basic test', async() => {
            await transpileCode('console.log("Hello, world!")');
        });
        it('should fail on broken code', async() => {
            const brokenCode = `
                let x: string = 'foo';
                x = 1337;
            `;
            let thrown = false;
            try {
                await transpileCode(brokenCode);
            } catch (err) {
                thrown = true;
            }
            assert.ok(thrown);
        });
    });
    describe('positive', () => {
        it('collection-creation', async() => {
            const code = codeBase + `
                (async() => {
                    const myDb: RxDatabase = await create({
                        name: 'mydb',
                        adapter: 'memory',
                        multiInstance: false,
                        ignoreDuplicate: false
                    });
                    const mySchema: SchemaJSON = ${JSON.stringify(schemas.human)};
                    const myCollection: RxCollection<any> = await myDb.collection({
                        name: 'humans',
                        schema: mySchema,
                        autoMigrate: false
                    });
                })();
            `;
            await transpileCode(code);
        });
    });
});<commit_msg>ADD tests for #329<commit_after>/**
 * this checks if typings work as expected
 */
import assert from 'assert';
import * as schemas from './../helper/schemas';

describe('typings.test.js', () => {
    const codeBase = `
        import {create, RxDatabase, RxCollection, RxDocument, SchemaJSON} from '../';
    `;
    const transpileCode = async(code) => {
        const spawn = require('child-process-promise').spawn;
        const stdout = [];
        const stderr = [];
        const promise = spawn('ts-node', [
            '--compilerOptions', '{"target":"es6"}',
            '-p', code
        ]);
        const childProcess = promise.childProcess;
        childProcess.stdout.on('data', data => stdout.push(data.toString()));
        childProcess.stderr.on('data', data => stderr.push(data.toString()));
        try {
            await promise;
        } catch (err) {
            throw new Error(`could not run
                # Error: ${err}
                # Output: ${stdout}
                # ErrOut: ${stderr}
                `);
        }
    };

    describe('basic', () => {
        it('should sucess on basic test', async() => {
            await transpileCode('console.log("Hello, world!")');
        });
        it('should fail on broken code', async() => {
            const brokenCode = `
                let x: string = 'foo';
                x = 1337;
            `;
            let thrown = false;
            try {
                await transpileCode(brokenCode);
            } catch (err) {
                thrown = true;
            }
            assert.ok(thrown);
        });
    });
    describe('positive', () => {
        it('collection-creation', async() => {
            const code = codeBase + `
                (async() => {
                    const myDb: RxDatabase = await create({
                        name: 'mydb',
                        adapter: 'memory',
                        multiInstance: false,
                        ignoreDuplicate: false
                    });
                    const mySchema: SchemaJSON = ${JSON.stringify(schemas.human)};
                    const myCollection: RxCollection<any> = await myDb.collection({
                        name: 'humans',
                        schema: mySchema,
                        autoMigrate: false,
                    });
                })();
            `;
            await transpileCode(code);
        });

        it('should know the orm-methods of an object', async() => {
            const code = codeBase + `
                declare interface RxHeroDocumentType {
                    name?: string;
                    color?: string;
                    maxHP?: number;
                    hp?: number;
                    team?: string;
                    skills?: Array<{
                        name?: string,
                        damage?: string
                    }>;

                    // ORM methods
                    foo(): string;
                };
                declare type RxHeroDocument = RxDocument<RxHeroDocumentType>;
                (async() => {
                    const myDb: RxDatabase = await create({
                        name: 'mydb',
                        adapter: 'memory',
                        multiInstance: false,
                        ignoreDuplicate: false
                    });
                    const mySchema: SchemaJSON = ${JSON.stringify(schemas.human)};
                    const myCollection: RxCollection<RxHeroDocument> = await myDb.collection({
                        name: 'humans',
                        schema: mySchema,
                        autoMigrate: false,
                        methods: {
                            foo: () => 'bar'
                        }
                    });
                    const oneDoc = await myCollection.findOne().exec();
                    const x: string = oneDoc.foo();
                })();
            `;
            await transpileCode(code);
        });
    });
});
{'fraction_non_alphanumeric': 0.12583605537408618, 'fraction_numerical': 0.0020220874163944624, 'mean_word_length': 1.18856364874064, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521072', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1504, 'n_words': 364}