Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/server/lib/cloud/exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Bluebird from 'bluebird'
import pkg from '@packages/root'
import api from './api'
import user from './user'
import system from '../util/system'
import * as system from '../util/system'
import { stripPath } from './strip_path'

const { serializeError } = require('serialize-error')
Expand Down
11 changes: 6 additions & 5 deletions packages/server/lib/controllers/xhrs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseContentType } from '@packages/net-stubbing/lib/server/util'
import _ from 'lodash'
import Promise from 'bluebird'
import fixture from '../fixture'
import { get as fixtureGet } from '../fixture'

const fixturesRe = /^(fx:|fixture:)/

Expand Down Expand Up @@ -70,18 +70,19 @@ export = {
return respond()
},

_get (resp: string, config: { fixturesFolder: string }): Promise<{ data: any, encoding?: string }> {
const options: { encoding?: string } = {}
_get (resp: string, config: { fixturesFolder: string }): Promise<{ data: any, encoding?: BufferEncoding }> {
const options: { encoding?: BufferEncoding } = {}

const file = resp.replace(fixturesRe, '')

const [filePath, encoding] = file.split(',')

if (encoding) {
options.encoding = encoding
options.encoding = encoding as BufferEncoding
}

return fixture.get(config.fixturesFolder, filePath, options)
// @ts-expect-error - bluebird to promise type mismatch
return fixtureGet(config.fixturesFolder, filePath, options)
.then((bytes: any) => {
return {
data: bytes,
Expand Down
64 changes: 0 additions & 64 deletions packages/server/lib/files.js

This file was deleted.

69 changes: 69 additions & 0 deletions packages/server/lib/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import path from 'path'
import { fs } from './util/fs'

export async function readFile (projectRoot: string, options: { file: string, encoding?: BufferEncoding } = { file: '', encoding: 'utf8' }) {
const filePath = path.resolve(projectRoot, options.file)

// https://github.com/cypress-io/cypress/issues/1558
// If no encoding is specified, then Cypress has historically defaulted
// to `utf8`, because of it's focus on text files. This is in contrast to
// NodeJs, which defaults to binary. We allow users to pass in `null`
// to restore the default node behavior.
try {
let contents

if (path.extname(filePath) === '.json' && options.encoding !== null) {
contents = await fs.readJsonAsync(filePath, options.encoding === undefined ? 'utf8' : options.encoding)
} else {
contents = await fs.readFileAsync(filePath, {
encoding: options.encoding === undefined ? 'utf8' : options.encoding,
})
}

return {
contents,
filePath,
}
} catch (err) {
err.originalFilePath = options.file
err.filePath = filePath
throw err
}
}

export async function readFiles (projectRoot: string, options: { files: { path: string, encoding?: BufferEncoding }[] } = { files: [] }) {
const files = await Promise.all(options.files.map(async (file) => {
const { contents, filePath } = await readFile(projectRoot, {
file: file.path,
encoding: file.encoding,
})

return {
...file,
filePath,
contents,
}
}))

return files
}

export async function writeFile (projectRoot: string, options: { fileName: string, contents: string, encoding?: BufferEncoding, flag?: string } = { fileName: '', contents: '', encoding: 'utf8', flag: 'w' }) {
const filePath = path.resolve(projectRoot, options.fileName)
const writeOptions = {
encoding: options.encoding === undefined ? 'utf8' : options.encoding,
flag: options.flag || 'w',
}

try {
await fs.outputFile(filePath, options.contents, writeOptions)

return {
contents: options.contents,
filePath,
}
} catch (err) {
err.filePath = filePath
throw err
}
}
212 changes: 0 additions & 212 deletions packages/server/lib/fixture.js

This file was deleted.

Loading
Loading