Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject into tsconfig.client.test.js and fix injecting test_typings into tsconfig.client.js #1828

Closed
Koslun opened this issue Apr 25, 2016 · 1 comment

Comments

@Koslun
Copy link
Member

Koslun commented Apr 25, 2016

Item Version
generator-angular-fullstack 3.6.1
Node 4.4.2
npm 3.8.7
Operating System Ubuntu 15.10
MongoDB 3.0
Item Answer
Transpiler TypeScript
Markup HTML
CSS SCSS
Router ngRoute
Build Tool Gulp
Client Tests Jasmine
DB MongoDB
Auth Y
Bootstrap Y
BootstrapUI Y
SocketIO Y

Used the above configuration but think this should apply for all Gulp and TypeScript flavors.

When running the tasks serve, build, watch, inject or directly running inject:tsconfig the tsconfig.client.js file is updated with all non-test ts files on the client side, along with both the regular typings and the test typings for the client side.

tsconfig.client.test.js is however never really updated with injections in the same way.

I would thus first suggest to change the injection of the tsconfig.client.js to only inject the regular typings, while a new task injects the test typings and all test ts files on the client side into tsconfig.client.test.js. Would then further add the new task to the inject task.

Did this change locally both in a fresh copy and in my own more advanced app. Working fine so far. Changes are as seen below.

Notes:
I would imagine inject:tsconfig and inject:tsconfigTest could be refactored to reduce duplicate code where one would further instead like to use the "filesGlob" in each tsConfig rather than write down the same thing again.

Should probably also do injection before tests and not really necessarily inject the test code for the serve and serve:debug tasks.

//in gulpfile.babel.js
gulp.task('inject', cb => {
    runSequence(['inject:js', 'inject:css', 'inject:scss', 'inject:tsconfig', 'inject:tsconfigTest'], cb);
});
//gulpfile.babel.js
//the changed task
gulp.task('inject:tsconfig', () => {
    let src = gulp.src([
        `${clientPath}/**/!(*.spec|*.mock).ts`, 
        `!${clientPath}/bower_components/**/*`,
        `${clientPath}/typings/**/*.d.ts`,
        `!${clientPath}/test_typings/**/*.d.ts` //added this
    ], {read: false})
        .pipe(plugins.sort());

    return gulp.src('./tsconfig.client.json')
        .pipe(plugins.inject(src, {
            starttag: '"files": [',
            endtag: ']',
            transform: (filepath, file, i, length) => {
                return `"${filepath.substr(1)}"${i + 1 < length ? ',' : ''}`;
            }
        }))
        .pipe(gulp.dest('./'));
});


//the new task
gulp.task('inject:tsconfigTest', () => {
    let src = gulp.src([
        `${clientPath}/**/+(*.spec|*.mock).ts`,
        `!${clientPath}/bower_components/**/*`,
        `!${clientPath}/typings/**/*.d.ts`,
        `${clientPath}/test_typings/**/*.d.ts`
    ], {read: false})
        .pipe(plugins.sort());

    return gulp.src('./tsconfig.client.test.json')
        .pipe(plugins.inject(src, {
            starttag: '"files": [',
            endtag: ']',
            transform: (filepath, file, i, length) => {
                return `"${filepath.substr(1)}"${i + 1 < length ? ',' : ''}`;
            }
        }))
        .pipe(gulp.dest('./'));
});

Should I take the time to do a PR with the shown changes or a variant of them?

@Koslun
Copy link
Member Author

Koslun commented Apr 25, 2016

Found a racing condition bug that probably needs fixing before that. Will create a separate issue when I come home for that. Think I can do a PR for both tomorrow.

Issue has to do with task transpile:client and task constant needing to have been run before task copy:constant. So quick-fix should just be adding dependency: gulp.task('copy:constant', ['constant'], () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants