Alexander Mills
Alexander Mills

Reputation: 100290

Big NPM repo - need to put large testsuite in separate project?

I have an NPM project (let's call it "X") that's pushing 15K lines. The testsuite for the project is probably close to 4K lines. The tests are all in the test folder. I'd like to avoid publishing the test directory to NPM so people don't have to install the extra 4K+ lines of code. This will save diskspace and make people happy because I can advertise a smaller footprint.

I think there's a couple of options:

  1. In the past I tried deleting folders when pushing to master on Github and to NPM - this was a version control nightmare when trying to merge hotfixes back into development (as far as my experience dictates). I don't think I want to revisit this. Deleting the test directory when moving to the master branch might be a disaster.

  2. I can move the tests to an entirely different NPM project. This seems like a much better idea. However, I am not sure how to do this exactly.

Does anyone have experience with this and is there a good solution? Maybe a 3rd way?

Upvotes: 0

Views: 56

Answers (1)

Freyja
Freyja

Reputation: 40904

I'd recommend that you keep your test cases in the same repository, and you can still keep them there while not publishing them to npm. There are two ways to tell npm which files to publish:

First, you can add the files and directories you want to publish to the "files" field of package.json. For instance, if you have a dist directory where all code you want to publish is (which would often be the case if you run your code through Babel, Typescript, a minifier etc.), your package.json may look something like this:

{
   ...
   "files": [
     "dist"
   ]
}

Files and directories not in this list will not be published. Some files, such as package.json, README, CHANGELOG and LICENSE, are always published regardless of this setting.

Secondly, you can add files and directories you don't want to publish to the .npmignore file, which works similar to the .gitignore file. For instance, if you (as in your case) don't want to publish files in the test/ directory, your .npmignore file may look like this:

test/

Again, the files package.json, README, CHANGELOG and LICENSE will always be published regardless of your .npmignore file.

Which of these options you use is up to you, and either may be more suitable for different project structures.

Upvotes: 3

Related Questions