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

test: Fix Windows Kitchen Sink #897

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"meow": "^9.0.0",
"ncp": "^2.0.0",
"prettier": "3.3.3",
"rimraf": "3.0.2",
"write-file-atomic": "^4.0.0"
"rimraf": "3.0.2"
},
"devDependencies": {
"@npm/types": "^2.0.0",
Expand All @@ -72,7 +71,6 @@
"@types/rimraf": "^3.0.0",
"@types/sinon": "^17.0.0",
"@types/tmp": "^0.2.0",
"@types/write-file-atomic": "^4.0.0",
"c8": "^10.1.2",
"cross-spawn": "^7.0.3",
"fs-extra": "^11.0.0",
Expand Down
5 changes: 2 additions & 3 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import * as inquirer from 'inquirer';
import * as path from 'path';
import {ncp} from 'ncp';
import * as util from 'util';
import * as writeFileAtomic from 'write-file-atomic';

import {
getPkgManagerCommand,
Expand Down Expand Up @@ -168,7 +167,7 @@ async function writePackageJson(
): Promise<void> {
options.logger.log('Writing package.json...');
if (!options.dryRun) {
await writeFileAtomic('./package.json', formatJson(packageJson));
await fs.promises.writeFile('./package.json', formatJson(packageJson));
}
const preview = {
scripts: packageJson.scripts,
Expand Down Expand Up @@ -216,7 +215,7 @@ async function generateConfigFile(
if (writeFile) {
options.logger.log(`Writing ${filename}...`);
if (!options.dryRun) {
await writeFileAtomic(filename, contents);
await fs.promises.writeFile(filename, contents);
}
options.logger.log(contents);
}
Expand Down
21 changes: 15 additions & 6 deletions test/kitchen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
const execOpts = {
cwd: `${stagingPath}${path.sep}kitchen`,
encoding: 'utf8' as BufferEncoding,
};
cwd: path.join(stagingPath, 'kitchen'),
encoding: 'utf8',
} as const;

const action = process.platform !== 'win32' ? describe : describe.skip;

action('🚰 kitchen sink', () => {
const fixturesPath = path.join('test', 'fixtures');
const gtsPath = path.join('node_modules', '.bin', 'gts');
const kitchenPath = path.join(stagingPath, 'kitchen');
const kitchenPath = execOpts.cwd;

// Create a staging directory with temp fixtures used to test on a fresh application.
before(() => {
console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`);
console.log('directory pre-pack:', fs.readdirSync('.'));
cp.execSync('npm pack');
const tarball = `${pkg.name}-${pkg.version}.tgz`;
fs.renameSync(tarball, 'gts.tgz');
Expand All @@ -36,6 +37,7 @@
fs.moveSync('gts.tgz', targetPath);
fs.copySync(fixturesPath, path.join(stagingPath, path.sep));
});

// CLEAN UP - remove the staging directory when done.
after('cleanup staging', () => {
if (!keep) {
Expand Down Expand Up @@ -75,9 +77,15 @@
it('should use as a non-locally installed module', () => {
// Use from a directory different from where we have locally installed. This
// simulates use as a globally installed module.
const GTS = path.resolve(stagingPath, 'kitchen/node_modules/.bin/gts');
const GTS = path.resolve(
stagingPath,
'kitchen',
'node_modules',
'.bin',
'gts'

Check failure on line 85 in test/kitchen.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
const tmpDir = tmp.dirSync({keep, unsafeCleanup: true});
const opts = {cwd: path.join(tmpDir.name, 'kitchen')};
const opts = {cwd: path.join(tmpDir.name, 'kitchen')} as const;

// Copy test files.
fs.copySync(fixturesPath, tmpDir.name);
Expand All @@ -86,6 +94,7 @@
path.join(stagingPath, 'gts.tgz'),
path.join(tmpDir.name, 'gts.tgz'),
);

// It's important to use `-n` here because we don't want to overwrite
// the version of gts installed, as it will trigger the npm install.
spawn.sync(GTS, ['init', '-n'], opts);
Expand Down
Loading